HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-2.5.9/spec/mspec/lib/mspec/runner/tag.rb
class SpecTag
  attr_accessor :tag, :comment, :description

  def initialize(string=nil)
    parse(string) if string
  end

  def parse(string)
    m = /^([^()#:]+)(\(([^)]+)?\))?:(.*)$/.match string
    @tag, @comment, description = m.values_at(1, 3, 4) if m
    @description = unescape description
  end

  def unescape(str)
    return unless str
    if str[0] == ?" and str[-1] == ?"
      str[1..-2].gsub('\n', "\n")
    else
      str
    end
  end

  def escape(str)
    if str.include? "\n"
      %["#{str.gsub("\n", '\n')}"]
    else
      str
    end
  end

  def to_s
    "#{@tag}#{ "(#{@comment})" if @comment }:#{escape @description}"
  end

  def ==(o)
    @tag == o.tag and @comment == o.comment and @description == o.description
  end
end