Class: C11n::Exporter::Yaml

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Yaml

Returns a new instance of Yaml.



6
7
8
9
# File 'lib/c11n/exporter/yaml.rb', line 6

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

Instance Method Details

#export(translations, locale) ⇒ Object



19
20
21
22
23
# File 'lib/c11n/exporter/yaml.rb', line 19

def export(translations, locale)
  deserialized_translations = C11n::Conversion::ComposedKeyDeserializer.new(translations.translations_for(locale)).deserialize
  file.print(YAML.dump(locale => deserialized_translations))
  file.close
end

#fileObject



15
16
17
# File 'lib/c11n/exporter/yaml.rb', line 15

def file
  @file ||= File.new(@path, 'w')
end

#path_for(locale) ⇒ Object



11
12
13
# File 'lib/c11n/exporter/yaml.rb', line 11

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