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