Class: WeddingRegistryScraper::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/wedding_registry_scraper/registry.rb

Constant Summary collapse

PRICE_TYPES =
[
  FIXED_PRICE = 'Fixed price',
  VARIABLE_PRICE = 'Variable price',
]

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, params = {}) ⇒ Registry

Returns a new instance of Registry.



15
16
17
18
19
# File 'lib/wedding_registry_scraper/registry.rb', line 15

def initialize(url, params={})
  params.symbolize_keys!
  @url = url
  @debug = params[:debug] == true
end

Class Attribute Details

.display_nameObject (readonly)

Returns the value of attribute display_name.



11
12
13
# File 'lib/wedding_registry_scraper/registry.rb', line 11

def display_name
  @display_name
end

.domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/wedding_registry_scraper/registry.rb', line 12

def domain
  @domain
end

Instance Method Details

#get_itemsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wedding_registry_scraper/registry.rb', line 21

def get_items
  doc = get_registry

  get_products(doc).reduce({}) do |products, product|
    sku = get_sku(product)

    details = {
      :name => get_name(product),
      :remaining => get_remaining(product),
      :desired => get_desired(product),
      :url => get_url(product),
      :image_url => get_image_url(product),
      :registry_name => self.class.display_name,
      :fulfilled => fulfilled?(product),
      :price_type => price_type(product),
      :price_value => get_price(product),
    }

    products.merge! sku => details
  end
end