Class: PoParser::Comment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/poparser/comment.rb', line 3

def type
  @type
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/poparser/comment.rb', line 3

def value
  @value
end

Instance Method Details

#inspectObject



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_strObject



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