Class: Newegg::Store

Inherits:
Api
  • Object
show all
Defined in:
lib/newegg/store.rb

Constant Summary

Constants inherited from Api

Api::DefaultUserAgent, Api::UserAgents

Instance Attribute Summary collapse

Attributes inherited from Api

#_categories, #_id, #_stores, #conn

Instance Method Summary collapse

Methods inherited from Api

#banners, #client_config, #combo_deals, #connection, #country, #daily_deal, #details, #exclusive_deals, #keywords, #navigate, #power_search, #power_search_content, #query, #reviews, #search, #shell_shockers, #shell_shockers_new, #shop_all_navigation, #shop_more_navigation, #shopping_guide, #specifications, #spotlight, #spotlights, #store_content, #store_navigate, #stores

Constructor Details

#initialize(title, store_department, store_id, show_see_all_deals) ⇒ Store

Returns a new instance of Store.



5
6
7
8
9
10
11
# File 'lib/newegg/store.rb', line 5

def initialize(title, store_department, store_id, show_see_all_deals)
  self.title = title
  self.store_department = store_department
  self.store_id = store_id
  self.show_see_all_deals = show_see_all_deals
  self.categories = []
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



3
4
5
# File 'lib/newegg/store.rb', line 3

def categories
  @categories
end

#show_see_all_dealsObject

Returns the value of attribute show_see_all_deals.



3
4
5
# File 'lib/newegg/store.rb', line 3

def show_see_all_deals
  @show_see_all_deals
end

#store_departmentObject

Returns the value of attribute store_department.



3
4
5
# File 'lib/newegg/store.rb', line 3

def store_department
  @store_department
end

#store_idObject

Returns the value of attribute store_id.



3
4
5
# File 'lib/newegg/store.rb', line 3

def store_id
  @store_id
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/newegg/store.rb', line 3

def title
  @title
end

Instance Method Details

#get_categories(newegg = Newegg) ⇒ Object



13
14
15
16
# File 'lib/newegg/store.rb', line 13

def get_categories(newegg = Newegg)
  self.categories = newegg.categories(self.store_id).freeze if self.categories.empty?
  self.categories
end

#to_h(newegg = Newegg) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/newegg/store.rb', line 18

def to_h(newegg = Newegg)
  @h ||= begin
    categories_hash = []
    get_categories(newegg).each do |c|
      categories_hash << c.to_h
    end
    {
      :title              => title,
      :store_department   => store_department,
      :store_id           => store_id,
      :show_see_all_deals => show_see_all_deals,
      :categories         => categories_hash
    }.freeze
  end
end