Class: PLU
- Inherits:
-
Object
- Object
- PLU
- Defined in:
- lib/plu.rb,
lib/plu/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.all ⇒ Object
TODO more items.
Instance Method Summary collapse
- #gm? ⇒ Boolean
-
#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.
4 5 6 |
# File 'lib/plu.rb', line 4 def initialize(number) @number = number.to_s end |
Class Method Details
.all ⇒ Object
TODO more items
29 30 31 32 33 34 35 36 37 |
# File 'lib/plu.rb', line 29 def self.all @all ||= begin all = {} CSV.foreach File.("../../plu_codes.csv", __FILE__), headers: true do |row| all[row["PLU Code"]] = row["Name"] end all end end |
Instance Method Details
#gm? ⇒ Boolean
20 21 22 |
# File 'lib/plu.rb', line 20 def gm? modifier == "8" end |
#name ⇒ Object
12 13 14 |
# File 'lib/plu.rb', line 12 def name self.class.all[base] end |
#organic? ⇒ Boolean
16 17 18 |
# File 'lib/plu.rb', line 16 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
8 9 10 |
# File 'lib/plu.rb', line 8 def valid? /\A[89]?[34]\d{3}\z/.match(@number) end |