Class: Spaceship::Tunes::LanguageItem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#identifierObject

title or description



5
6
7
# File 'lib/spaceship/tunes/language_item.rb', line 5

def identifier
  @identifier
end

#original_arrayObject

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

#inspectObject



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

#keysArray

Returns An array containing all languages that are already available.

Returns:

  • (Array)

    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

#languagesArray

Returns An array containing all languages that are already available alias for keys.

Returns:

  • (Array)

    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_sObject



51
52
53
# File 'lib/spaceship/tunes/language_item.rb', line 51

def to_s
  inspect
end