Class: C11n::Importer::Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/c11n/importer/yaml.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Yaml

Returns a new instance of Yaml.



8
9
10
11
12
# File 'lib/c11n/importer/yaml.rb', line 8

def initialize(options = {})
  @base_path = options[:base_path]
  @path = options[:path]
  @types = {}
end

Instance Method Details

#categoriesObject



33
34
35
# File 'lib/c11n/importer/yaml.rb', line 33

def categories
  {}
end

#fileObject



18
19
20
# File 'lib/c11n/importer/yaml.rb', line 18

def file
  File.open(@path, 'r')
end

#importObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/c11n/importer/yaml.rb', line 22

def import
  raw_yaml = YAML.load(file.read)
  translations = C11n::Conversion::Serializer.new(raw_yaml.values.first).serialize

  translations.each do |key, translation|
    @types[key] = C11n::Types::ARRAY if translation.is_a?(Array)
  end

  { raw_yaml.keys.first => translations }
end

#path_for(locale) ⇒ Object



14
15
16
# File 'lib/c11n/importer/yaml.rb', line 14

def path_for(locale)
  @path || "#{@base_path}/#{locale}.yml"
end

#typesObject



37
38
39
# File 'lib/c11n/importer/yaml.rb', line 37

def types
  @types
end