Class: Spaceship::Tunes::LanguageItem

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

Instance Method Summary collapse

Methods included from LanguageItemHashBehavior

#each

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

#identifierObject

title or description



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

def identifier
  @identifier
end

#original_arrayObject

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

#inspectObject



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

#keysArray

Returns An array containing all languages that are already available.

Returns:

  • (Array)

    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

#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



44
45
46
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 44

def languages
  keys
end

#to_sObject



56
57
58
# File 'spaceship/lib/spaceship/tunes/language_item.rb', line 56

def to_s
  inspect
end