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.
7 8 9 10 11 12 |
# File 'lib/poparser/message.rb', line 7 def initialize(type, value) @type = type @value = value remove_empty_line end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/poparser/message.rb', line 5 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/poparser/message.rb', line 5 def value @value end |
Instance Method Details
#inspect ⇒ Object
38 39 40 |
# File 'lib/poparser/message.rb', line 38 def inspect @value end |
#str ⇒ Object
14 15 16 |
# File 'lib/poparser/message.rb', line 14 def str @value.is_a?(Array) ? @value.join : @value end |
#to_s(with_label = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/poparser/message.rb', line 18 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
34 35 36 |
# File 'lib/poparser/message.rb', line 34 def to_str @value.is_a?(Array) ? @value.join : @value end |