Class: Cnf::Catalog

Inherits:
Object
  • Object
show all
Extended by:
Enumerable, Forwardable
Defined in:
lib/cnf/catalog.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dataObject



24
25
26
# File 'lib/cnf/catalog.rb', line 24

def data
  @data ||= Cnf.amazon.map { |country| new(country.to_h) }
end

.filter_by_marketplace(marketplace_ids) ⇒ Object



67
68
69
# File 'lib/cnf/catalog.rb', line 67

def self.filter_by_marketplace(marketplace_ids)
  Catalog.select { |catalog| catalog.in? marketplace_ids }
end

.find_by_name(name) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/cnf/catalog.rb', line 75

def self.find_by_name(name)
  return TestCatalog.call if name == 'www.amazon.com-richardson'
  return AbebooksCatalog.find_by_name(name) if name =~ /abebooks/
  return MiraklCatalog.find_by_name(name) if name =~ /libro/
  return NearfineCatalog.find_by_name(name) if name =~ /nearfine/
  Catalog.find { |catalog| catalog.name == name }
end

.find_catalog_by_country_code(country_code) ⇒ Object



71
72
73
# File 'lib/cnf/catalog.rb', line 71

def self.find_catalog_by_country_code(country_code)
  Catalog.find { |catalog| catalog.country == country_code }
end

.namesObject



33
34
35
# File 'lib/cnf/catalog.rb', line 33

def self.names
  map(&:name) + Cnf::AbebooksCatalog.names
end

Instance Method Details

#active?Boolean



59
60
61
# File 'lib/cnf/catalog.rb', line 59

def active?
  Cnf.active_channels.include? marketplace.country_code
end

#countryObject



37
38
39
# File 'lib/cnf/catalog.rb', line 37

def country
  marketplace.country_code
end

#currencyObject



41
42
43
# File 'lib/cnf/catalog.rb', line 41

def currency
  marketplace.currency_code
end

#in?(marketplace_ids) ⇒ Boolean



55
56
57
# File 'lib/cnf/catalog.rb', line 55

def in?(marketplace_ids)
  active? && marketplace_ids.include?(marketplace_id)
end

#languageObject



63
64
65
# File 'lib/cnf/catalog.rb', line 63

def language
  marketplace.language_code
end

#marketplace_idObject



51
52
53
# File 'lib/cnf/catalog.rb', line 51

def marketplace_id
  marketplace.id
end

#nameObject



29
30
31
# File 'lib/cnf/catalog.rb', line 29

def name
  marketplace.hostname
end

#supported_parent_offer?(_) ⇒ Boolean



45
46
47
# File 'lib/cnf/catalog.rb', line 45

def supported_parent_offer?(_)
  true
end