Class: RussianPost::Barcode::Base
- Inherits:
-
Object
- Object
- RussianPost::Barcode::Base
- Extended by:
- Forwardable
- Defined in:
- lib/russianpost/barcode/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#barcode ⇒ Object
readonly
Returns the value of attribute barcode.
-
#digits ⇒ Object
readonly
Returns the value of attribute digits.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(barcode) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(barcode) ⇒ Base
Returns a new instance of Base.
16 17 18 19 |
# File 'lib/russianpost/barcode/base.rb', line 16 def initialize() @barcode = .strip.upcase @digits = .scan(/\d/).map { |d| d.to_i } end |
Instance Attribute Details
#barcode ⇒ Object (readonly)
Returns the value of attribute barcode.
10 11 12 |
# File 'lib/russianpost/barcode/base.rb', line 10 def @barcode end |
#digits ⇒ Object (readonly)
Returns the value of attribute digits.
10 11 12 |
# File 'lib/russianpost/barcode/base.rb', line 10 def digits @digits end |
Class Method Details
.format ⇒ Object
12 13 14 |
# File 'lib/russianpost/barcode/base.rb', line 12 def self.format /.*/ end |
Instance Method Details
#to_s ⇒ Object
25 26 27 |
# File 'lib/russianpost/barcode/base.rb', line 25 def to_s end |
#valid? ⇒ Boolean
21 22 23 |
# File 'lib/russianpost/barcode/base.rb', line 21 def valid? ( =~ self.class.format || false) && digits.last == checkdigit end |