Class: SpecTag

Inherits:
Object show all
Defined in:
lib/extensions/mspec/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/extensions/mspec/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/extensions/mspec/mspec/runner/tag.rb', line 2

def comment
  @comment
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#tagObject

Returns the value of attribute tag.



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

def tag
  @tag
end

Instance Method Details

#==(o) ⇒ Object



35
36
37
# File 'lib/extensions/mspec/mspec/runner/tag.rb', line 35

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

#escape(str) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/extensions/mspec/mspec/runner/tag.rb', line 23

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

#parse(string) ⇒ Object



8
9
10
11
12
# File 'lib/extensions/mspec/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



31
32
33
# File 'lib/extensions/mspec/mspec/runner/tag.rb', line 31

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

#unescape(str) ⇒ Object



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

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