class PoParser::Comment

Attributes

type[RW]
value[RW]

Public Class Methods

new(type, value) click to toggle source
# File lib/poparser/comment.rb, line 7
def initialize(type, value)
  @type = type
  @value = value

  # these behave more like messages
  remove_empty_line if /^previous_/.match?(@type.to_s)
end

Public Instance Methods

inspect() click to toggle source
# File lib/poparser/comment.rb, line 53
def inspect
  @value
end
to_s(with_label = false) click to toggle source
# File lib/poparser/comment.rb, line 15
def to_s(with_label = false)
  return to_str unless with_label

  if @value.is_a? Array
    if /^previous_/.match?(@type.to_s) # these behave more like messages
      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 /^previous_/.match?(@type.to_s) # 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_str() click to toggle source
# File lib/poparser/comment.rb, line 41
def to_str
  if @value.is_a?(Array)
    if /^previous_/.match?(@type.to_s) # these behave more like messages
      @value.join
    else
      @value.join("\n")
    end
  else
    @value
  end
end

Private Instance Methods

remove_empty_line() click to toggle source
# File lib/poparser/comment.rb, line 59
def remove_empty_line
  @value.shift if @value.is_a?(Array) && @value.first == ''
end