Class: Anpo::POEntry
- Inherits:
-
Object
- Object
- Anpo::POEntry
- Defined in:
- lib/anpo.rb
Instance Attribute Summary collapse
-
#comments ⇒ Object
Returns the value of attribute comments.
Instance Method Summary collapse
- #comments_to_s ⇒ Object
-
#initialize(lines = nil) ⇒ POEntry
constructor
A new instance of POEntry.
- #is_fuzzy? ⇒ Boolean
- #is_header? ⇒ Boolean
- #is_translated? ⇒ Boolean
- #msgid ⇒ Object
- #msgid=(id) ⇒ Object
- #msgid_to_s ⇒ Object
- #msgstr ⇒ Object
- #msgstr=(str) ⇒ Object
- #msgstr_to_s ⇒ Object
- #on_changed(&proc) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(lines = nil) ⇒ POEntry
Returns a new instance of POEntry.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |
Instance Attribute Details
#comments ⇒ Object
Returns the value of attribute comments.
11 12 13 |
# File 'lib/anpo.rb', line 11 def comments @comments end |
Instance Method Details
#comments_to_s ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/anpo.rb', line 98 def comments_to_s if @comments.empty? "" else @comments.join("\n") + "\n" end end |
#is_fuzzy? ⇒ Boolean
66 67 68 |
# File 'lib/anpo.rb', line 66 def is_fuzzy? comments.grep(/#,.*fuzzy/).length != 0 end |
#is_header? ⇒ Boolean
74 75 76 |
# File 'lib/anpo.rb', line 74 def is_header? @msgid and @msgid.empty? and !@msgstr.empty? end |
#is_translated? ⇒ Boolean
70 71 72 |
# File 'lib/anpo.rb', line 70 def is_translated? (@msgid and !@msgid.empty?) and (@msgstr and !@msgstr.empty?) end |
#msgid ⇒ Object
17 18 19 |
# File 'lib/anpo.rb', line 17 def msgid @msgid.clone end |
#msgid=(id) ⇒ Object
21 22 23 24 25 26 |
# 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 ⇒ Object
78 79 80 81 82 83 84 85 86 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/anpo.rb', line 28 def msgstr @msgstr.clone end |
#msgstr=(str) ⇒ Object
32 33 34 35 36 37 |
# 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 ⇒ Object
88 89 90 91 92 93 94 95 96 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/anpo.rb', line 13 def on_changed(&proc) @change_listener.push(proc) end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/anpo.rb', line 106 def to_s comments_to_s + msgid_to_s + msgstr_to_s end |