Class: PLU

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

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Instance Method Summary collapse

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

.allObject



28
29
30
# File 'lib/plu.rb', line 28

def self.all
  @all ||= JSON.load_file(File.expand_path("../plu_codes.json", __dir__))
end

Instance Method Details

#nameObject



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

def name
  self.class.all[base]
end

#organic?Boolean

Returns:

  • (Boolean)


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

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)


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

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