Class: AdLocalize::Platform::PlatformFormatter
- Inherits:
-
Object
- Object
- AdLocalize::Platform::PlatformFormatter
- Defined in:
- lib/ad_localize/platform/platform_formatter.rb
Direct Known Subclasses
Constant Summary collapse
- PLURAL_KEY_SYMBOL =
:plural- SINGULAR_KEY_SYMBOL =
:singular- OPTIONS =
{output_path: ".."}
Instance Attribute Summary collapse
-
#default_locale ⇒ Object
readonly
Returns the value of attribute default_locale.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#platform_dir ⇒ Object
Returns the value of attribute platform_dir.
Instance Method Summary collapse
- #export(locale, data, export_extension, substitution_format) ⇒ Object
-
#initialize(default_locale, output_path) ⇒ PlatformFormatter
constructor
A new instance of PlatformFormatter.
- #platform ⇒ Object
Constructor Details
#initialize(default_locale, output_path) ⇒ PlatformFormatter
Returns a new instance of PlatformFormatter.
10 11 12 13 14 15 |
# File 'lib/ad_localize/platform/platform_formatter.rb', line 10 def initialize(default_locale, output_path) @default_locale = default_locale.to_sym @output_path = output_path # Must be set before platform_dir @platform_dir = export_base_directory.join(platform.to_s) create_platform_dir end |
Instance Attribute Details
#default_locale ⇒ Object (readonly)
Returns the value of attribute default_locale.
8 9 10 |
# File 'lib/ad_localize/platform/platform_formatter.rb', line 8 def default_locale @default_locale end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
8 9 10 |
# File 'lib/ad_localize/platform/platform_formatter.rb', line 8 def output_path @output_path end |
#platform_dir ⇒ Object
Returns the value of attribute platform_dir.
7 8 9 |
# File 'lib/ad_localize/platform/platform_formatter.rb', line 7 def platform_dir @platform_dir end |
Instance Method Details
#export(locale, data, export_extension, substitution_format) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ad_localize/platform/platform_formatter.rb', line 21 def export(locale, data, export_extension, substitution_format) locale = locale.to_sym formatted_data = data.each_with_object({}) do |(key, wording), hash_acc| hash_acc[locale.to_s] = {} unless hash_acc.key? locale.to_s if wording.dig(locale)&.key? :singular value = ios_converter(wording.dig(locale, :singular)) hash_acc[locale.to_s][key.to_s] = value end if wording.dig(locale)&.key? :plural hash_acc[locale.to_s][key.to_s] = {} unless hash_acc[locale.to_s].key? key.to_s wording.dig(locale, :plural).each do |plural_type, plural_text| value = ios_converter(plural_text) hash_acc[locale.to_s][key.to_s][plural_type.to_s] = value end end end platform_dir.join("#{locale.to_s}.#{export_extension}").open("w") do |file| yield(formatted_data, file) end AdLocalize::LOGGER.log(:debug, :black, "#{platform.to_s.upcase} [#{locale}] ---> DONE!") end |
#platform ⇒ Object
17 18 19 |
# File 'lib/ad_localize/platform/platform_formatter.rb', line 17 def platform raise 'Please override me!' end |