Class: PLU

Inherits:
Object
  • Object
show all
Defined in:
lib/plu.rb,
lib/plu/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

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

.allObject

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.expand_path("../../plu_codes.csv", __FILE__), headers: true do |row|
      all[row["PLU Code"]] = row["Name"]
    end
    all
  end
end

Instance Method Details

#gm?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/plu.rb', line 20

def gm?
  modifier == "8"
end

#nameObject



12
13
14
# File 'lib/plu.rb', line 12

def name
  self.class.all[base]
end

#organic?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/plu.rb', line 16

def organic?
  modifier == "9"
end

#retailer_assigned?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/plu.rb', line 24

def retailer_assigned?
  name.to_s.start_with?("Retailer Assigned")
end

#valid?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/plu.rb', line 8

def valid?
  /\A[89]?[34]\d{3}\z/.match(@number)
end