Class: C11n::Importer::Yaml
- Inherits:
-
Object
- Object
- C11n::Importer::Yaml
- Defined in:
- lib/c11n/importer/yaml.rb
Instance Method Summary collapse
- #categories ⇒ Object
- #file ⇒ Object
- #import ⇒ Object
-
#initialize(options = {}) ⇒ Yaml
constructor
A new instance of Yaml.
- #path_for(locale) ⇒ Object
- #types ⇒ Object
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( = {}) @base_path = [:base_path] @path = [:path] @types = {} end |
Instance Method Details
#categories ⇒ Object
33 34 35 |
# File 'lib/c11n/importer/yaml.rb', line 33 def categories {} end |
#file ⇒ Object
18 19 20 |
# File 'lib/c11n/importer/yaml.rb', line 18 def file File.open(@path, 'r') end |
#import ⇒ Object
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 |
#types ⇒ Object
37 38 39 |
# File 'lib/c11n/importer/yaml.rb', line 37 def types @types end |