Class: Opera::MobileStore::PaymentInfo

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

Direct Known Subclasses

Check, PayPal, Wired

Defined Under Namespace

Classes: Check, PayPal, Wired

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InspectableAttributes

#inspect

Class Method Details

.build_from_nokogiri_node(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/opera/mobile_store/payment_info.rb', line 16

def self.build_from_nokogiri_node(node)
  if node.present?
    type = node.xpath("string(@type)").strip.downcase

    case type
    when "check"  then Check.build_from_nokogiri_node node
    when "wired"  then Wired.build_from_nokogiri_node node
    when "paypal" then PayPal.build_from_nokogiri_node node
    when "none"   then nil
    else raise "WTF?"
    end
  end
end

.deserialize(serializable_hash) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/opera/mobile_store/payment_info.rb', line 30

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

    case field_name
    when 'payment_info'
      field_value = PaymentInfo.deserialize field_value
    end

    hsh[field_name] = field_value
    hsh
  end

  self.new attributes_hash
end

Instance Method Details

#typeObject



11
12
13
14
# File 'lib/opera/mobile_store/payment_info.rb', line 11

def type
  ref_type = self.class.name.demodulize.downcase
  ref_type == 'pay_pal' ? 'paypal' : ref_type
end