Class: PoParser::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/poparser/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#strObject



13
14
15
# File 'lib/poparser/message.rb', line 13

def str
  @str.is_a?(Array) ? @str.join : @str
end

#typeObject

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_strObject



32
33
34
# File 'lib/poparser/message.rb', line 32

def to_str
  @str.is_a?(Array) ? @str.join : @str
end