Class: AdLocalize::Entities::LocaleWording

Inherits:
Object
  • Object
show all
Defined in:
lib/ad_localize/entities/locale_wording.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale:, is_default:) ⇒ LocaleWording

Returns a new instance of LocaleWording.



7
8
9
10
11
12
13
14
# File 'lib/ad_localize/entities/locale_wording.rb', line 7

def initialize(locale:, is_default:)
  @locale = locale
  @is_default = is_default
  @singulars = {} # label => SimpleWording
  @info_plists = {} # label => SimpleWording
  @plurals = Hash.new { |hash, key| hash[key] = {} } # label: String => { variant_name: String => SimpleWording }
  @adaptives = Hash.new { |hash, key| hash[key] = {} } # label: String => { variant_name: String => SimpleWording }
end

Instance Attribute Details

#adaptivesObject (readonly)

Returns the value of attribute adaptives.



5
6
7
# File 'lib/ad_localize/entities/locale_wording.rb', line 5

def adaptives
  @adaptives
end

#info_plistsObject (readonly)

Returns the value of attribute info_plists.



5
6
7
# File 'lib/ad_localize/entities/locale_wording.rb', line 5

def info_plists
  @info_plists
end

#is_defaultObject (readonly)

Returns the value of attribute is_default.



5
6
7
# File 'lib/ad_localize/entities/locale_wording.rb', line 5

def is_default
  @is_default
end

#localeObject (readonly)

Returns the value of attribute locale.



5
6
7
# File 'lib/ad_localize/entities/locale_wording.rb', line 5

def locale
  @locale
end

#pluralsObject (readonly)

Returns the value of attribute plurals.



5
6
7
# File 'lib/ad_localize/entities/locale_wording.rb', line 5

def plurals
  @plurals
end

#singularsObject (readonly)

Returns the value of attribute singulars.



5
6
7
# File 'lib/ad_localize/entities/locale_wording.rb', line 5

def singulars
  @singulars
end

Instance Method Details

#add_wording(key:, value:, comment:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ad_localize/entities/locale_wording.rb', line 16

def add_wording(key:, value:, comment:)
  wording = SimpleWording.new(key: key, value: value, comment: comment)

  case key.type
  when WordingType::PLURAL
    @plurals[key.label][key.variant_name] = wording
  when WordingType::ADAPTIVE
    @adaptives[key.label][key.variant_name] = wording
  when WordingType::INFO_PLIST
    @info_plists[key.label] = wording
  else
    @singulars[key.label] = wording
  end
end

#to_sObject



31
32
33
34
35
36
37
# File 'lib/ad_localize/entities/locale_wording.rb', line 31

def to_s
  "Locale\nis default: #{is_default}\n==========\n" +
    "Singulars\n#{singulars}\n==========\n" +
    "InfoPlists\n#{info_plists}\n==========\n" +
    "Plurals\n#{plurals}\n==========\n" +
    "Adaptives\n#{adaptives}\n==========\n"
end