Class: Opera::MobileStore::ProductImage

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InspectableAttributes

#inspect

Instance Attribute Details

#heightObject

All attributes are Read-Only…



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

def height
  @height
end

#typeObject

All attributes are Read-Only…



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

def type
  @type
end

#urlObject

All attributes are Read-Only…



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

def url
  @url
end

#widthObject

All attributes are Read-Only…



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

def width
  @width
end

Class Method Details

.build_from_nokogiri_node(node) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opera/mobile_store/product_image.rb', line 22

def self.build_from_nokogiri_node(node)

  data = {
    type: node.name,
    url: node.text.strip
  }

  # Extract width + height data:
  width = node.xpath("string(@width)")
  height = node.xpath("string(@height)")
  data[:width] = width.to_i if width.present?
  data[:height] = width.to_i if height.present?

  self.new data
end

Instance Method Details

#attributesObject



14
15
16
17
18
19
20
# File 'lib/opera/mobile_store/product_image.rb', line 14

def attributes
  [:type, :width, :height, :url].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