Class: PoToJson

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(files, glue = "|") ⇒ PoToJson



33
34
35
36
# File 'lib/po_to_json.rb', line 33

def initialize(files, glue = "|")
  @files = files
  @glue = glue
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



31
32
33
# File 'lib/po_to_json.rb', line 31

def files
  @files
end

#glueObject

Returns the value of attribute glue.



31
32
33
# File 'lib/po_to_json.rb', line 31

def glue
  @glue
end

#optionsObject

Returns the value of attribute options.



31
32
33
# File 'lib/po_to_json.rb', line 31

def options
  @options
end

Instance Method Details

#flush_bufferObject



74
75
76
77
78
79
80
81
# File 'lib/po_to_json.rb', line 74

def flush_buffer
  return unless buffer[:msgid]

  build_trans
  assign_trans

  reset_buffer
end

#generate_for_jed(language, overwrite = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/po_to_json.rb', line 38

def generate_for_jed(language, overwrite = {})
  @options = parse_options(overwrite.merge(language: language))
  @parsed ||= inject_meta(parse_document)

  generated = build_json_for(build_jed_for(@parsed))

  [
    @options[:variable_locale_scope] ? "var" : "",
    "#{@options[:variable]} = #{@options[:variable]} || {};",
    "#{@options[:variable]}['#{@options[:language]}'] = #{generated};"
  ].join(" ")
end

#generate_for_json(language, overwrite = {}) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/po_to_json.rb', line 51

def generate_for_json(language, overwrite = {})
  @options = parse_options(overwrite.merge(language: language))
  @parsed ||= inject_meta(parse_document)

  generated = build_json_for(build_json_for(@parsed))

  raise "Not implemented yet, current value is #{generated}!"
end

#parse_documentObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/po_to_json.rb', line 60

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_headerObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/po_to_json.rb', line 83

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_headerObject



95
96
97
98
99
100
101
102
# File 'lib/po_to_json.rb', line 95

def reject_header
  if values[""].nil? || values[""][0].nil?
    values[""] = {}
    true
  else
    false
  end
end