Class: Opera::MobileStore::Build

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

Defined Under Namespace

Classes: UsesSDK

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

#billingObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def billing
  @billing
end

#build_update_dateObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def build_update_date
  @build_update_date
end

#filesObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def files
  @files
end

#idObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def id
  @id
end

#installer_typeObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def installer_type
  @installer_type
end

#languagesObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def languages
  @languages
end

#localesObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def locales
  @locales
end

#nameObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def name
  @name
end

#package_nameObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def package_name
  @package_name
end

#platformObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def platform
  @platform
end

#supported_screensObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def supported_screens
  @supported_screens
end

#typeObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def type
  @type
end

#used_permissionsObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def used_permissions
  @used_permissions
end

#uses_sdkObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def uses_sdk
  @uses_sdk
end

#version_codeObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def version_code
  @version_code
end

#version_nameObject

All attributes are Read-Only…



14
15
16
# File 'lib/opera/mobile_store/build.rb', line 14

def version_name
  @version_name
end

Class Method Details

.build_from_nokogiri_node(node) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/opera/mobile_store/build.rb', line 113

def self.build_from_nokogiri_node(node)

  version_code = node.xpath("string(version_code)")

  data = {
    id: node.xpath("string(@id)").to_i,
    name: node.xpath("string(name)").strip,
    platform: node.xpath("string(platform)").strip,
    type: node.xpath("string(type)").strip,
    installer_type: node.xpath("string(installer_type)").strip,
    package_name: node.xpath("string(package_name)").strip,
    version_name: node.xpath("string(version_name)").strip,
    version_code: version_code.present? ? version_code.to_i : nil,
    build_update_date: Time.parse(node.xpath "string(build_update_date)"),

    files: node.xpath("files/file").map do |f|
      BuildFile.build_from_nokogiri_node f
    end,

    languages: node.xpath("languages/language").map do |language|
      language.attributes["code"].to_s.strip
    end,

    supported_screens: node.xpath("supports_screens/screen").map do |scr|
      scr.text.strip
    end,

    used_permissions: node.xpath("uses_permissions/permission").map do |per|
      per.text.strip
    end,

    locales: node.xpath("locales/locale").map do |locale_node|
      locale_node.text.strip
    end
  }.select { |key, val| val.present? }

  data[:billing] = node.xpath("string(billing)").to_i > 0

  uses_sdk_node = node.xpath("uses_sdk").first
  if uses_sdk_node.present?
    uses_sdk_attributes = {
      min:    uses_sdk_node.xpath("string(@min)").strip,
      target: uses_sdk_node.xpath("string(@target)").strip,
      max:    uses_sdk_node.xpath("string(@max)").strip
    }.select { |k,v| v.present? }.inject({}) do |hsh, keyval|
      key, val = keyval
      hsh[key] = val.to_i
      hsh
    end
    data[:uses_sdk] = UsesSDK.new uses_sdk_attributes
  end

  self.new data
end

.deserialize(serializable_hash) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/opera/mobile_store/build.rb', line 95

def self.deserialize(serializable_hash)
  attributes_hash = serializable_hash.inject({}) do |hsh, keyval|
    field_name, field_value = keyval

    case field_name
    when 'files'
      field_value = field_value.map do |item_serializable_hash|
        BuildFile.deserialize item_serializable_hash
      end
    end

    hsh[field_name] = field_value
    hsh
  end

  self.new attributes_hash
end

Instance Method Details

#attributesObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/opera/mobile_store/build.rb', line 64

def attributes
  [
    :id, :name, :platform, :type, :installer_type, :package_name,
    :version_name, :version_code, :build_update_date, :files, :billing,
    :languages, :uses_sdk, :supported_screens, :used_permissions, :locales
  ].inject({}) do |hash, field_name|
    field_value = self.public_send field_name
    hash[field_name.to_s] = field_value if field_value.present?
    hash
  end
end

#compatibilityObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/opera/mobile_store/build.rb', line 43

def compatibility
  @compatibility ||= begin
    compat_query = Opera::MobileStore::Compatibility.where(build_id: id)
    compat = compat_query.first
    if uses_sdk.present?
      compat.min_sdk_version = uses_sdk.min
      compat.max_sdk_version = uses_sdk.max
      compat.target_sdk_version = uses_sdk.target
    end
    compat
  end if id.present?
end

#min_sdk_versionObject



56
57
58
59
60
61
62
# File 'lib/opera/mobile_store/build.rb', line 56

def min_sdk_version
  @min_sdk_version ||= if uses_sdk.present?
    uses_sdk.min
  else
    compatibility.min_sdk_version
  end
end

#serializable_hash(options = nil) ⇒ Object

Override of serializable_hash:

This override will prevent dumping special objects to the hash:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/opera/mobile_store/build.rb', line 79

def serializable_hash(options = nil)
  attributes.inject({}) do |shsh, keyval|
    field_name, field_value = keyval

    case field_name
    when 'uses_sdk'
      field_value = field_value.serializable_hash
    when 'files' # Array of special objects
      field_value = field_value.map(&:serializable_hash)
    end

    shsh[field_name] = field_value
    shsh
  end
end