Class: YellowPages::Merchant
- Inherits:
-
Object
- Object
- YellowPages::Merchant
- Defined in:
- lib/yellow_pages/merchant.rb
Class Method Summary collapse
- .lookup ⇒ Object
-
.merchants ⇒ Hash
Returns all the merchants and their network IDs.
Instance Method Summary collapse
-
#icon ⇒ String?
Returns an SVG logo icon of the merchant.
-
#in_dataset? ⇒ Boolean
Returns true if the merchant is in the dataset.
-
#initialize(network_id:) ⇒ Merchant
constructor
A new instance of Merchant.
-
#name ⇒ String?
Returns merchant name.
Constructor Details
#initialize(network_id:) ⇒ Merchant
Returns a new instance of Merchant.
32 33 34 35 36 |
# File 'lib/yellow_pages/merchant.rb', line 32 def initialize(network_id:) @network_id = network_id YellowPages.missing_merchant_reporter&.call(@network_id) unless in_dataset? end |
Class Method Details
.lookup ⇒ Object
38 39 40 |
# File 'lib/yellow_pages/merchant.rb', line 38 def self.lookup(...) new(...) end |
.merchants ⇒ Hash
Returns all the merchants and their network IDs
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yellow_pages/merchant.rb', line 11 def self.merchants @merchants ||= begin path = Pathname.new(__dir__).join("merchants.yaml") yaml = YAML.load_file(path) yaml.flat_map do |merchant| next if merchant["name"].nil? merchant["network_ids"].map do |nid| filename = merchant["name"].gsub(/[ '-]/, "").downcase filepath = Pathname.new(__dir__).join("../assets/icons/#{filename}.svg") [nid, {name: merchant["name"], icon_filepath: filepath}] end end.compact.to_h end end |
Instance Method Details
#icon ⇒ String?
Returns an SVG logo icon of the merchant
52 53 54 55 56 57 58 59 60 |
# File 'lib/yellow_pages/merchant.rb', line 52 def icon @icon ||= begin path = merchant&.fetch(:icon_filepath) File.read(path) if path rescue Errno::ENOENT nil end end |
#in_dataset? ⇒ Boolean
Returns true if the merchant is in the dataset
64 65 66 |
# File 'lib/yellow_pages/merchant.rb', line 64 def in_dataset? !merchant.nil? end |
#name ⇒ String?
Returns merchant name
45 46 47 |
# File 'lib/yellow_pages/merchant.rb', line 45 def name merchant&.fetch(:name) end |