Class: TinValid::DenmarkTin
- Inherits:
-
Object
- Object
- TinValid::DenmarkTin
- Includes:
- Helpers
- Defined in:
- lib/tin_valid/denmark_tin.rb
Instance Attribute Summary collapse
-
#birth_date ⇒ Object
readonly
Returns the value of attribute birth_date.
-
#tin ⇒ Object
readonly
Returns the value of attribute tin.
Instance Method Summary collapse
-
#initialize(tin:, birth_date: nil) ⇒ DenmarkTin
constructor
A new instance of DenmarkTin.
-
#valid? ⇒ Boolean
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(tin:, birth_date: nil) ⇒ DenmarkTin
Returns a new instance of DenmarkTin.
7 8 9 10 |
# File 'lib/tin_valid/denmark_tin.rb', line 7 def initialize(tin:, birth_date: nil) @tin = tin @birth_date = birth_date end |
Instance Attribute Details
#birth_date ⇒ Object (readonly)
Returns the value of attribute birth_date.
12 13 14 |
# File 'lib/tin_valid/denmark_tin.rb', line 12 def birth_date @birth_date end |
#tin ⇒ Object (readonly)
Returns the value of attribute tin.
12 13 14 |
# File 'lib/tin_valid/denmark_tin.rb', line 12 def tin @tin end |
Instance Method Details
#valid? ⇒ Boolean
rubocop:disable Metrics/AbcSize
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tin_valid/denmark_tin.rb', line 15 def valid? match = MATCHER.match(tin) return false unless match return false if tin == "0000000000" if birth_date year = "#{birth_century}#{match[:year]}" return false if birth_date != date(year, match[:month], match[:day]) return false unless check_serial(match[:serial], match[:year]) end match[:check].to_i == checksum end |