class Anpo::POEntry

Attributes

comments[RW]

Public Class Methods

new(lines = nil) click to toggle source
# File lib/anpo.rb, line 39
def initialize(lines = nil)
  state = ""
  @change_listener = []
  @msgid = nil
  @msgstr = nil
  @comments = []

  unless lines.nil?
    lines.each do |l|
      if l.start_with?("msgid")
        state = "msgid"
        @msgid = l.gsub("msgid \"", "").gsub(/"\s*$/, "")
      elsif l.start_with?("msgstr")
        state = "msgstr"
        @msgstr = l.gsub("msgstr \"", "").gsub(/"\s*$/, "")
      elsif l.start_with?("#")
        state = "comment"
        @comments.push(l.gsub("\n", ""))
      elsif state == "msgid"
        @msgid = @msgid + "\n" + l.gsub(/^\s*"/, "").gsub(/"\s*$/, "")
      elsif state == "msgstr"
        @msgstr = @msgstr + "\n" + l.gsub(/^\s*"/, "").gsub(/"\s*$/, "")
      end
    end
  end
end

Public Instance Methods

comments_to_s() click to toggle source
# File lib/anpo.rb, line 98
def comments_to_s
  if @comments.empty?
    ""
  else
    @comments.join("\n") + "\n"
  end
end
is_fuzzy?() click to toggle source
# File lib/anpo.rb, line 66
def is_fuzzy?
  comments.grep(/#,.*fuzzy/).length != 0
end
is_header?() click to toggle source
# File lib/anpo.rb, line 74
def is_header?
  @msgid and @msgid.empty? and !@msgstr.empty?
end
is_translated?() click to toggle source
# File lib/anpo.rb, line 70
def is_translated?
  (@msgid and !@msgid.empty?) and (@msgstr and !@msgstr.empty?)
end
msgid() click to toggle source
# File lib/anpo.rb, line 17
def msgid
  @msgid.clone
end
msgid=(id) click to toggle source
# File lib/anpo.rb, line 21
def msgid=(id)
  @change_listener.each do |prc|
    prc.call(self, id, @msgstr)
  end
  @msgid = id
end
msgid_to_s() click to toggle source
# File lib/anpo.rb, line 78
def msgid_to_s
  if @msgid.nil?
    ""
  elsif is_header?
    "msgid \"\"\n"
  else
    "msgid " + @msgid.split("\n").collect { |x| "\"#{x}\"" }.join("\n") + "\n"
  end
end
msgstr() click to toggle source
# File lib/anpo.rb, line 28
def msgstr
  @msgstr.clone
end
msgstr=(str) click to toggle source
# File lib/anpo.rb, line 32
def msgstr=(str)
  @change_listener.each do |prc|
    prc.call(self, @msgid, str)
  end
  @msgstr = str
end
msgstr_to_s() click to toggle source
# File lib/anpo.rb, line 88
def msgstr_to_s
  if @msgid.nil?
    ""
  elsif @msgstr.empty?
    "msgstr \"\"\n"
  else
    "msgstr " + @msgstr.split("\n").collect { |x| "\"#{x}\"" }.join("\n") + "\n"
  end
end
on_changed(&proc) click to toggle source
# File lib/anpo.rb, line 13
def on_changed(&proc)
  @change_listener.push(proc)
end
to_s() click to toggle source
# File lib/anpo.rb, line 106
def to_s
  comments_to_s + msgid_to_s + msgstr_to_s
end