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, str) ⇒ Comment

Returns a new instance of Comment.



5
6
7
8
# File 'lib/poparser/comment.rb', line 5

def initialize(type, str)
  @type = type
  @str  = str
end

Instance Attribute Details

#strObject

Returns the value of attribute str.



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

def str
  @str
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#to_s(with_label = false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/poparser/comment.rb', line 10

def to_s(with_label = false)
  return @str unless with_label
  if @str.is_a? Array
    string = []
    @str.each do |str|
      string << "#{COMMENTS_LABELS[@type]} #{str}\n".gsub(/[^\S\n]+$/, '')
    end
    return string.join
  else
    # removes the space but not newline at the end
    "#{COMMENTS_LABELS[@type]} #{@str}\n".gsub(/[^\S\n]+$/, '')
  end
end

#to_strObject



24
25
26
# File 'lib/poparser/comment.rb', line 24

def to_str
  @str
end