Class: Opera::MobileStore::DevicePlatform

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Serialization, InspectableAttributes, Opera::MobileStoreSDK::APIAccessible, Opera::MobileStoreSDK::IdentityMapable
Defined in:
lib/opera/mobile_store/device_platform.rb

Constant Summary collapse

OPERA_PLATFORM_TO_ANDROID_SDK_MAPPINGS =
{
  'platform-android-1-0' => 1,
  'platform-android-1-1' => 2,
  'platform-android-1-5' => 3,
  'platform-android-1-6' => 4,
  'platform-android-2-0' => 5,
  'platform-android-2-0-1' => 6,
  'platform-android-2-1' => 7,
  'platform-android-2-2' => 8,
  'platform-android-2-3' => 9,
  'platform-android-2-3-3-plus' => 10,
  'platform-android-3-0' => 11,
  'platform-android-3-1' => 12,
  'platform-android-3-2' => 13,
  'platform-android-4-0' => 14,
  'platform-android-4-0-3-plus' => 15,
  'platform-android-4-1-plus' => 16,
  'platform-android-4-2-plus' => 17,
  'platform-android-4-3' => 18,
  'platform-android-4-4' => 19,
  'platform-android-4-4-plus' => 20
}.freeze
ANDROID_SDK_LEVEL_VERSION_CODES =
{
  22 => 'LOLLIPOP_MR1',
  21 => 'LOLLIPOP',
  20 => 'KITKAT_WATCH',
  19 => 'KITKAT',
  18 => 'JELLY_BEAN_MR2',
  17 => 'JELLY_BEAN_MR1',
  16 => 'JELLY_BEAN',
  15 => 'ICE_CREAM_SANDWICH_MR1',
  14 => 'ICE_CREAM_SANDWICH',
  13 => 'HONEYCOMB_MR2',
  12 => 'HONEYCOMB_MR1',
  11 => 'HONEYCOMB',
  10 => 'GINGERBREAD_MR1',
   9 => 'GINGERBREAD',
   8 => 'FROYO',
   7 => 'ECLAIR',
   6 => 'ECLAIR_0_1',
   5 => 'ECLAIR',
   4 => 'DONUT',
   3 => 'CUPCAKE',
   2 => 'BASE_1_1',
   1 => 'BASE'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Opera::MobileStoreSDK::IdentityMapable

#initialize

Methods included from InspectableAttributes

#inspect

Instance Attribute Details

#codeObject

All attributes are Read-Only…



64
65
66
# File 'lib/opera/mobile_store/device_platform.rb', line 64

def code
  @code
end

#idObject

All attributes are Read-Only…



64
65
66
# File 'lib/opera/mobile_store/device_platform.rb', line 64

def id
  @id
end

#nameObject

All attributes are Read-Only…



64
65
66
# File 'lib/opera/mobile_store/device_platform.rb', line 64

def name
  @name
end

Class Method Details

.build_from_nokogiri_node(node) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/opera/mobile_store/device_platform.rb', line 84

def self.build_from_nokogiri_node(node)
  data = {
    id:   node.xpath("number(@id)").to_i,
    code: node.xpath("string(@code)").strip,
    name: node.text.strip
  }.select { |key, val| val.present? }

  self.new data
end

Instance Method Details

#android_sdk_levelObject



74
75
76
# File 'lib/opera/mobile_store/device_platform.rb', line 74

def android_sdk_level
  OPERA_PLATFORM_TO_ANDROID_SDK_MAPPINGS[code] if code['platform-android'].present?
end

#android_version_codeObject



78
79
80
# File 'lib/opera/mobile_store/device_platform.rb', line 78

def android_version_code
  ANDROID_SDK_LEVEL_VERSION_CODES[android_sdk_level]
end

#attributesObject



66
67
68
69
70
71
72
# File 'lib/opera/mobile_store/device_platform.rb', line 66

def attributes
  [:id, :code, :name].inject({}) do |hash, field_name|
    field_value = self.public_send field_name
    hash[field_name.to_s] = field_value unless field_value.nil?
    hash
  end
end