Class: PLU
- Inherits:
-
Object
- Object
- PLU
- Defined in:
- lib/plu.rb,
lib/plu/version.rb
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(number) ⇒ PLU
constructor
A new instance of PLU.
- #name ⇒ Object
- #organic? ⇒ Boolean
- #retailer_assigned? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(number) ⇒ PLU
Returns a new instance of PLU.
8 9 10 |
# File 'lib/plu.rb', line 8 def initialize(number) @number = number.to_s end |
Class Method Details
.all ⇒ Object
28 29 30 |
# File 'lib/plu.rb', line 28 def self.all @all ||= JSON.load_file(File.("../plu_codes.json", __dir__)) end |
Instance Method Details
#name ⇒ Object
16 17 18 |
# File 'lib/plu.rb', line 16 def name self.class.all[base] end |
#organic? ⇒ Boolean
20 21 22 |
# File 'lib/plu.rb', line 20 def organic? modifier == "9" end |
#retailer_assigned? ⇒ Boolean
24 25 26 |
# File 'lib/plu.rb', line 24 def retailer_assigned? name.to_s.start_with?("Retailer Assigned") end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/plu.rb', line 12 def valid? /\A[89]?[34]\d{3}\z/.match(@number) end |