Class: TurkishId
- Inherits:
-
Object
- Object
- TurkishId
- Defined in:
- lib/turkish_id.rb,
lib/turkish_id/version.rb
Constant Summary collapse
- VERSION =
"1.7.0"
Instance Attribute Summary collapse
-
#checksum ⇒ Object
readonly
Returns the value of attribute checksum.
-
#elder_relative ⇒ Object
readonly
Returns the value of attribute elder_relative.
-
#id_number ⇒ Object
readonly
Returns the value of attribute id_number.
-
#younger_relative ⇒ Object
readonly
Returns the value of attribute younger_relative.
Instance Method Summary collapse
- #foreigner_not_in_registry?(given_name, surname, day_of_birth, month_of_birth, year_of_birth) ⇒ Boolean
- #foreigner_registered?(given_name, surname, year_of_birth, month_of_birth, day_of_birth) ⇒ Boolean
-
#initialize(id_number) ⇒ TurkishId
constructor
A new instance of TurkishId.
- #not_in_registry?(given_name, surname, year_of_birth) ⇒ Boolean
- #registered?(given_name, surname, year_of_birth) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(id_number) ⇒ TurkishId
Returns a new instance of TurkishId.
9 10 11 12 13 14 |
# File 'lib/turkish_id.rb', line 9 def initialize(id_number) @id_number = get_id_array(id_number) @checksum = calculate_checksum(@id_number) @elder_relative = generate_relatives(@id_number, :up) @younger_relative = generate_relatives(@id_number, :down) end |
Instance Attribute Details
#checksum ⇒ Object (readonly)
Returns the value of attribute checksum.
7 8 9 |
# File 'lib/turkish_id.rb', line 7 def checksum @checksum end |
#elder_relative ⇒ Object (readonly)
Returns the value of attribute elder_relative.
7 8 9 |
# File 'lib/turkish_id.rb', line 7 def elder_relative @elder_relative end |
#id_number ⇒ Object (readonly)
Returns the value of attribute id_number.
7 8 9 |
# File 'lib/turkish_id.rb', line 7 def id_number @id_number end |
#younger_relative ⇒ Object (readonly)
Returns the value of attribute younger_relative.
7 8 9 |
# File 'lib/turkish_id.rb', line 7 def younger_relative @younger_relative end |
Instance Method Details
#foreigner_not_in_registry?(given_name, surname, day_of_birth, month_of_birth, year_of_birth) ⇒ Boolean
35 36 37 |
# File 'lib/turkish_id.rb', line 35 def foreigner_not_in_registry?(given_name, surname, day_of_birth, month_of_birth, year_of_birth) !valid? || !query_foreigner_registry(given_name, surname, day_of_birth, month_of_birth, year_of_birth) end |
#foreigner_registered?(given_name, surname, year_of_birth, month_of_birth, day_of_birth) ⇒ Boolean
31 32 33 |
# File 'lib/turkish_id.rb', line 31 def foreigner_registered?(given_name, surname, year_of_birth, month_of_birth, day_of_birth) valid? && query_foreigner_registry(given_name, surname, year_of_birth, month_of_birth, day_of_birth) end |
#not_in_registry?(given_name, surname, year_of_birth) ⇒ Boolean
27 28 29 |
# File 'lib/turkish_id.rb', line 27 def not_in_registry?(given_name, surname, year_of_birth) !valid? || !query_government_registry(given_name, surname, year_of_birth) end |
#registered?(given_name, surname, year_of_birth) ⇒ Boolean
23 24 25 |
# File 'lib/turkish_id.rb', line 23 def registered?(given_name, surname, year_of_birth) valid? && query_government_registry(given_name, surname, year_of_birth) end |
#valid? ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/turkish_id.rb', line 16 def valid? return false if @id_number.length != 11 || @id_number.first.zero? return false if @id_number.values_at(9, 10) != @checksum ||= calculate_checksum(@id_number) true end |