Class: YellowPages::Category
- Inherits:
-
Object
- Object
- YellowPages::Category
- Defined in:
- lib/yellow_pages/category.rb
Class Method Summary collapse
-
.categories_by_code ⇒ Hash
All categories keyed by their MCC code.
-
.categories_by_key ⇒ Hash
All categories keyed by their stripe key.
- .lookup ⇒ Object
Instance Method Summary collapse
-
#code ⇒ String?
Returns category’s code.
-
#in_dataset? ⇒ Boolean
Returns true if the category is in the dataset.
-
#initialize(code: nil, key: nil) ⇒ Category
constructor
A new instance of Category.
-
#key ⇒ String?
Returns category’s key.
-
#name ⇒ String?
Returns category’s name.
Constructor Details
#initialize(code: nil, key: nil) ⇒ Category
Returns a new instance of Category.
33 34 35 36 37 |
# File 'lib/yellow_pages/category.rb', line 33 def initialize(code: nil, key: nil) raise ArgumentError, "Either code or key must be provided" if code.nil? && key.nil? @code, @key = code, key end |
Class Method Details
.categories_by_code ⇒ Hash
Returns all categories keyed by their MCC code.
9 10 11 12 13 14 15 16 17 |
# File 'lib/yellow_pages/category.rb', line 9 def self.categories_by_code @categories_by_code ||= begin path = Pathname.new(__dir__).join("categories.yaml") YAML.load_file(path).map do |code, obj| [code.to_s, obj.merge(code:).transform_keys(&:to_sym)] end.to_h end end |
.categories_by_key ⇒ Hash
Returns all categories keyed by their stripe key.
20 21 22 23 24 25 26 27 |
# File 'lib/yellow_pages/category.rb', line 20 def self.categories_by_key @categories_by_key ||= begin categories_by_code.map do |code, obj| [obj.fetch(:key), obj] end.to_h end end |
.lookup ⇒ Object
39 40 41 |
# File 'lib/yellow_pages/category.rb', line 39 def self.lookup(...) new(...) end |
Instance Method Details
#code ⇒ String?
Returns category’s code
46 47 48 |
# File 'lib/yellow_pages/category.rb', line 46 def code category&.fetch(:code) end |
#in_dataset? ⇒ Boolean
Returns true if the category is in the dataset
66 67 68 |
# File 'lib/yellow_pages/category.rb', line 66 def in_dataset? !category.nil? end |
#key ⇒ String?
Returns category’s key
60 61 62 |
# File 'lib/yellow_pages/category.rb', line 60 def key category&.fetch(:key) end |
#name ⇒ String?
Returns category’s name
53 54 55 |
# File 'lib/yellow_pages/category.rb', line 53 def name category&.fetch(:name) end |