Class: PoToJson
- Inherits:
-
Object
- Object
- PoToJson
- Defined in:
- lib/po_to_json/version.rb,
lib/po_to_json.rb
Overview
Copyright © 2012-2015 Dropmysite.com <dropmyemail.com> Copyright © 2015 Webhippie <www.webhippie.de>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Defined Under Namespace
Classes: Version
Instance Attribute Summary collapse
-
#buffer ⇒ Object
writeonly
Sets the attribute buffer.
-
#errors ⇒ Object
writeonly
Sets the attribute errors.
-
#files ⇒ Object
Returns the value of attribute files.
-
#glue ⇒ Object
Returns the value of attribute glue.
-
#lastkey ⇒ Object
writeonly
Sets the attribute lastkey.
-
#options ⇒ Object
Returns the value of attribute options.
-
#trans ⇒ Object
writeonly
Sets the attribute trans.
-
#values ⇒ Object
writeonly
Sets the attribute values.
Instance Method Summary collapse
- #flush_buffer ⇒ Object
- #generate_for_jed(language, overwrite = {}) ⇒ Object
- #generate_for_json(language, overwrite = {}) ⇒ Object
-
#initialize(files, glue = "|") ⇒ PoToJson
constructor
A new instance of PoToJson.
- #parse_document ⇒ Object
- #parse_header ⇒ Object
- #reject_header ⇒ Object
Constructor Details
#initialize(files, glue = "|") ⇒ PoToJson
Returns a new instance of PoToJson.
41 42 43 44 |
# File 'lib/po_to_json.rb', line 41 def initialize(files, glue = "|") @files = files @glue = glue end |
Instance Attribute Details
#buffer=(value) ⇒ Object
Sets the attribute buffer
37 38 39 |
# File 'lib/po_to_json.rb', line 37 def buffer=(value) @buffer = value end |
#errors=(value) ⇒ Object
Sets the attribute errors
35 36 37 |
# File 'lib/po_to_json.rb', line 35 def errors=(value) @errors = value end |
#files ⇒ Object
Returns the value of attribute files.
32 33 34 |
# File 'lib/po_to_json.rb', line 32 def files @files end |
#glue ⇒ Object
Returns the value of attribute glue.
33 34 35 |
# File 'lib/po_to_json.rb', line 33 def glue @glue end |
#lastkey=(value) ⇒ Object
Sets the attribute lastkey
38 39 40 |
# File 'lib/po_to_json.rb', line 38 def lastkey=(value) @lastkey = value end |
#options ⇒ Object
Returns the value of attribute options.
34 35 36 |
# File 'lib/po_to_json.rb', line 34 def @options end |
#trans=(value) ⇒ Object
Sets the attribute trans
39 40 41 |
# File 'lib/po_to_json.rb', line 39 def trans=(value) @trans = value end |
#values=(value) ⇒ Object
Sets the attribute values
36 37 38 |
# File 'lib/po_to_json.rb', line 36 def values=(value) @values = value end |
Instance Method Details
#flush_buffer ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/po_to_json.rb', line 81 def flush_buffer return unless buffer[:msgid] build_trans assign_trans reset_buffer end |
#generate_for_jed(language, overwrite = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/po_to_json.rb', line 46 def generate_for_jed(language, overwrite = {}) @options = (overwrite.merge(language: language)) @parsed ||= (parse_document) generated = build_json_for(build_jed_for(@parsed)) [ "var #{@options[:variable]} = #{@options[:variable]} || {};", "#{@options[:variable]}['#{@options[:language]}'] = #{generated};" ].join(" ") end |
#generate_for_json(language, overwrite = {}) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/po_to_json.rb', line 58 def generate_for_json(language, overwrite = {}) @options = (overwrite.merge(language: language)) @parsed ||= (parse_document) generated = build_json_for(build_json_for(@parsed)) fail "Not implemented yet, current value is #{generated}!" end |
#parse_document ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/po_to_json.rb', line 67 def parse_document reset_buffer reset_result File.foreach(files) do |line| matches_values_for(line.chomp) end flush_buffer parse_header values end |
#parse_header ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/po_to_json.rb', line 90 def parse_header return if reject_header values[""][0].split("\\n").each do |line| next if line.empty? build_header_for(line) end values[""] = headers end |
#reject_header ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/po_to_json.rb', line 101 def reject_header if values[""].nil? || values[""][0].nil? values[""] = {} true else false end end |