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.
5 6 7 8 |
# File 'lib/poparser/comment.rb', line 5 def initialize(type, value) @type = type @value = value end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/poparser/comment.rb', line 3 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/poparser/comment.rb', line 3 def value @value end |
Instance Method Details
#inspect ⇒ Object
48 49 50 |
# File 'lib/poparser/comment.rb', line 48 def inspect @value end |
#to_s(with_label = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/poparser/comment.rb', line 10 def to_s(with_label = false) return to_str unless with_label if @value.is_a? Array if @type.to_s =~ /^previous_/ # these behave more like messages remove_empty_line 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 @type.to_s =~ /^previous_/ # 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
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/poparser/comment.rb', line 36 def to_str if @value.is_a?(Array) if @type.to_s =~ /^previous_/ # these behave more like messages @value.join else @value.join("\n") end else @value end end |