lib/plu.rb in plu-0.0.1 vs lib/plu.rb in plu-0.0.2

- old
+ new

@@ -1,16 +1,17 @@ +require "csv" + class PLU def initialize(number) @number = number.to_s end def valid? /\A[89]?[34]\d{3}\z/.match(@number) end - # TODO more items def name self.class.all[base] end def organic? @@ -19,13 +20,18 @@ def gm? modifier == "8" end + # TODO more items def self.all - { - "4011" => "Bananas" - } + @all ||= begin + all = {} + CSV.foreach File.expand_path("../../plu_codes.csv", __FILE__), headers: true do |row| + all[row["PLU Code"]] = row["Name"] + end + all + end end protected def base