Class: Spaceship::Tunes::LanguageItem
- Inherits:
-
Object
- Object
- Spaceship::Tunes::LanguageItem
- Includes:
- LanguageItemHashBehavior
- Defined in:
- spaceship/lib/spaceship/tunes/language_item.rb,
precheck/lib/precheck/rule_processor.rb
Overview
Represents one attribute (e.g. name) of an app in multiple languages
Instance Attribute Summary collapse
-
#identifier ⇒ Object
title or description.
-
#original_array ⇒ Object
reference to original array.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #get_lang(lang) ⇒ Object
- #get_value(key: nil) ⇒ Object
-
#initialize(identifier, ref) ⇒ LanguageItem
constructor
A new instance of LanguageItem.
- #inspect ⇒ Object
-
#keys ⇒ Array
An array containing all languages that are already available.
-
#languages ⇒ Array
An array containing all languages that are already available alias for keys.
- #to_s ⇒ Object
Methods included from LanguageItemHashBehavior
Constructor Details
#initialize(identifier, ref) ⇒ LanguageItem
Returns a new instance of LanguageItem.
8 9 10 11 12 13 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 8 def initialize(identifier, ref) raise "ref is nil" if ref.nil? self.identifier = identifier.to_s self.original_array = ref end |
Instance Attribute Details
#identifier ⇒ Object
title or description
5 6 7 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 5 def identifier @identifier end |
#original_array ⇒ Object
reference to original array
6 7 8 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 6 def original_array @original_array end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 15 def [](key) get_value(key: key) end |
#[]=(key, value) ⇒ Object
19 20 21 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 19 def []=(key, value) get_lang(key)[identifier]['value'] = value end |
#get_lang(lang) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 27 def get_lang(lang) result = self.original_array.find do |current| lang = lang.to_s current['language'] == lang or current['localeCode'] == lang # Apple being consistent end return result if result raise "Language '#{lang}' is not activated / available for this app version." end |
#get_value(key: nil) ⇒ Object
23 24 25 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 23 def get_value(key: nil) get_lang(key)[identifier]['value'] end |
#inspect ⇒ Object
48 49 50 51 52 53 54 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 48 def inspect result = "" self.original_array.collect do |current| result += "#{current['language'] ||= current['localeCode']}: #{current.fetch(identifier, {}).fetch('value')}\n" end result end |
#keys ⇒ Array
Returns An array containing all languages that are already available.
38 39 40 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 38 def keys return self.original_array.map { |current| current['language'] ||= current['localeCode'] } # Apple being consistent end |
#languages ⇒ Array
Returns An array containing all languages that are already available alias for keys.
44 45 46 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 44 def languages keys end |
#to_s ⇒ Object
56 57 58 |
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 56 def to_s inspect end |