Class: SpecTag

Inherits:
Object show all
Defined in:
lib/mspec/runner/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = nil) ⇒ SpecTag

Returns a new instance of SpecTag.



4
5
6
# File 'lib/mspec/runner/tag.rb', line 4

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

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



2
3
4
# File 'lib/mspec/runner/tag.rb', line 2

def comment
  @comment
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/mspec/runner/tag.rb', line 2

def description
  @description
end

#tagObject

Returns the value of attribute tag.



2
3
4
# File 'lib/mspec/runner/tag.rb', line 2

def tag
  @tag
end

Instance Method Details

#==(o) ⇒ Object



29
30
31
# File 'lib/mspec/runner/tag.rb', line 29

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

#escape(str) ⇒ Object



20
21
22
23
# File 'lib/mspec/runner/tag.rb', line 20

def escape(str)
  str = %["#{str.gsub(/\n/, '\n')}"] if /\n/ =~ str
  str
end

#parse(string) ⇒ Object



8
9
10
11
12
# File 'lib/mspec/runner/tag.rb', line 8

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

#to_sObject



25
26
27
# File 'lib/mspec/runner/tag.rb', line 25

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

#unescape(str) ⇒ Object



14
15
16
17
18
# File 'lib/mspec/runner/tag.rb', line 14

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