Class: PoParser::Message
- Inherits:
-
Object
- Object
- PoParser::Message
- Defined in:
- lib/poparser/message.rb
Instance Attribute Summary collapse
- #str ⇒ Object
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, str) ⇒ Message
constructor
A new instance of Message.
- #to_s(with_label = false) ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(type, str) ⇒ Message
Returns a new instance of Message.
6 7 8 9 10 11 |
# File 'lib/poparser/message.rb', line 6 def initialize(type, str) @type = type @str = str remove_empty_line end |
Instance Attribute Details
#str ⇒ Object
13 14 15 |
# File 'lib/poparser/message.rb', line 13 def str @str.is_a?(Array) ? @str.join : @str end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/poparser/message.rb', line 3 def type @type end |
Instance Method Details
#to_s(with_label = false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/poparser/message.rb', line 17 def to_s(with_label = false) return @str unless with_label if @str.is_a? Array remove_empty_line # multiline messages should be started with an empty line lines = ["#{label} \"\"\n"] @str.each do |str| lines << "\"#{str}\"\n" end return lines.join else "#{label} \"#{@str}\"\n" end end |
#to_str ⇒ Object
32 33 34 |
# File 'lib/poparser/message.rb', line 32 def to_str @str.is_a?(Array) ? @str.join : @str end |