Class: PoParser::Comment
- Inherits:
-
Object
- Object
- PoParser::Comment
- Defined in:
- lib/poparser/comment.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(type, value) ⇒ Comment
constructor
A new instance of Comment.
- #inspect ⇒ Object
- #to_s(with_label = false) ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(type, value) ⇒ Comment
Returns a new instance of Comment.
7 8 9 10 11 12 13 |
# File 'lib/poparser/comment.rb', line 7 def initialize(type, value) @type = type @value = value # these behave more like messages remove_empty_line if /^previous_/.match?(@type.to_s) end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/poparser/comment.rb', line 5 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/poparser/comment.rb', line 5 def value @value end |
Instance Method Details
#inspect ⇒ Object
53 54 55 |
# File 'lib/poparser/comment.rb', line 53 def inspect @value end |
#to_s(with_label = false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/poparser/comment.rb', line 15 def to_s(with_label = false) return to_str unless with_label if @value.is_a? Array if /^previous_/.match?(@type.to_s) # these behave more like messages string = ["#{COMMENTS_LABELS[@type]} \"\"\n"] @value.each do |str| string << "#| \"#{str}\"\n".gsub(/[\p{Blank}]+$/, '') end else string = [] @value.each do |str| string << "#{COMMENTS_LABELS[@type]} #{str}\n".gsub(/[\p{Blank}]+$/, '') end end return string.join else if /^previous_/.match?(@type.to_s) # these behave more like messages "#{COMMENTS_LABELS[@type]} \"#{@value}\"\n".gsub(/[\p{Blank}]+$/, '') else # removes the space but not newline at the end "#{COMMENTS_LABELS[@type]} #{@value}\n".gsub(/[\p{Blank}]+$/, '') end end end |
#to_str ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/poparser/comment.rb', line 41 def to_str if @value.is_a?(Array) if /^previous_/.match?(@type.to_s) # these behave more like messages @value.join else @value.join("\n") end else @value end end |