Class: Spaceship::Tunes::LanguageItem
- Inherits:
-
Object
- Object
- Spaceship::Tunes::LanguageItem
- Defined in:
- lib/spaceship/tunes/language_item.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
-
#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
Constructor Details
#initialize(identifier, ref) ⇒ LanguageItem
Returns a new instance of LanguageItem.
8 9 10 11 12 13 |
# File '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 'lib/spaceship/tunes/language_item.rb', line 5 def identifier @identifier end |
#original_array ⇒ Object
reference to original array
6 7 8 |
# File 'lib/spaceship/tunes/language_item.rb', line 6 def original_array @original_array end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'lib/spaceship/tunes/language_item.rb', line 15 def [](key) get_lang(key)[identifier]['value'] end |
#[]=(key, value) ⇒ Object
19 20 21 |
# File 'lib/spaceship/tunes/language_item.rb', line 19 def []=(key, value) get_lang(key)[identifier]['value'] = value end |
#get_lang(lang) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/spaceship/tunes/language_item.rb', line 23 def get_lang(lang) result = self.original_array.find do |current| 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 |
#inspect ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/spaceship/tunes/language_item.rb', line 43 def inspect result = "" self.original_array.collect do |current| result += "#{current.fetch('language')}: #{current.fetch(identifier, {}).fetch('value')}\n" end result end |
#keys ⇒ Array
Returns An array containing all languages that are already available.
33 34 35 |
# File 'lib/spaceship/tunes/language_item.rb', line 33 def keys self.original_array.collect { |l| l.fetch('language') } end |
#languages ⇒ Array
Returns An array containing all languages that are already available alias for keys.
39 40 41 |
# File 'lib/spaceship/tunes/language_item.rb', line 39 def languages keys end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/spaceship/tunes/language_item.rb', line 51 def to_s inspect end |