Class: LetsShopMapper::Model::OpenSearch::Entry
- Inherits:
-
Object
- Object
- LetsShopMapper::Model::OpenSearch::Entry
- Defined in:
- lib/letsshop_mapper/model/opensearch/entry.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#delivery_times ⇒ Object
readonly
Returns the value of attribute delivery_times.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#discount ⇒ Object
readonly
Returns the value of attribute discount.
-
#facets ⇒ Object
readonly
Returns the value of attribute facets.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#older_price ⇒ Object
readonly
Returns the value of attribute older_price.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#product_condition ⇒ Object
readonly
Returns the value of attribute product_condition.
-
#supplier ⇒ Object
readonly
Returns the value of attribute supplier.
-
#thumb ⇒ Object
readonly
Returns the value of attribute thumb.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #get_facets_by(scope) ⇒ Object
-
#initialize(entry = nil) ⇒ Entry
constructor
A new instance of Entry.
- #parse(entry) ⇒ Object
- #to_s(localtime = true) ⇒ Object
Constructor Details
#initialize(entry = nil) ⇒ Entry
19 20 21 22 23 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 19 def initialize(entry = nil) @id, @link, @title, @description, @price, @thumb, @supplier, @delivery_times, @product_condition = nil @facets = [] parse(entry) if entry end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
10 11 12 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 10 def currency @currency end |
#delivery_times ⇒ Object (readonly)
Returns the value of attribute delivery_times.
16 17 18 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 16 def delivery_times @delivery_times end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 8 def description @description end |
#discount ⇒ Object (readonly)
Returns the value of attribute discount.
11 12 13 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 11 def discount @discount end |
#facets ⇒ Object (readonly)
Returns the value of attribute facets.
15 16 17 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 15 def facets @facets end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 5 def id @id end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
6 7 8 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 6 def link @link end |
#older_price ⇒ Object (readonly)
Returns the value of attribute older_price.
12 13 14 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 12 def older_price @older_price end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
9 10 11 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 9 def price @price end |
#product_condition ⇒ Object (readonly)
Returns the value of attribute product_condition.
17 18 19 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 17 def product_condition @product_condition end |
#supplier ⇒ Object (readonly)
Returns the value of attribute supplier.
14 15 16 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 14 def supplier @supplier end |
#thumb ⇒ Object (readonly)
Returns the value of attribute thumb.
13 14 15 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 13 def thumb @thumb end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 7 def title @title end |
Instance Method Details
#get_facets_by(scope) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 46 def get_facets_by(scope) results = [] @facets.each { |f| if f.type == scope then results << f end } return results end |
#parse(entry) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 25 def parse(entry) @id = entry.at('id').text @link = entry.at('link')['href'] @title = entry.at('title').text @description = entry.at('description').text @thumb =entry.at('letsshop/thumb').text @price = entry.at('letsshop/price').text @currency = entry.at('letsshop/price')['currency'] @discount = entry.at('letsshop/price')['discount'] @older_price = entry.at('letsshop/price')['older'] @delivery_times = entry.at('letsshop/delivery_times').text @product_condition = entry.at('letsshop/product_condition').text entry.children.search('Query').each do |f| @facets << Base::Facet::new(f) if !f['title'].index("supplier:").nil? @supplier = f['title'].gsub("supplier:","") end end end |
#to_s(localtime = true) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/letsshop_mapper/model/opensearch/entry.rb', line 54 def to_s(localtime = true) s = '' s += "Id: #{@id}\n" s += "Link: #{@link}\n" s += "Title: #{@title}\n" s += "Description: #{@description}\n" s += "Delivery times: #{@delivery_times}\n" s += "Product condition: #{@product_condition}\n" s += "Thumbnail: #{@thumb}\n" s += "Price: #{@price} #{@currency}\n" s += "Discount: #{@older_price} (#{@discount})\n" s += "Supplier: #{@supplier}\n" s += "----------------------------------\n" @facets.each { |i| s += i.to_s(localtime) } s += "\n" end |