Class: TurkishId

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

Constant Summary collapse

VERSION =
"1.7.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checksumObject (readonly)

Returns the value of attribute checksum.



7
8
9
# File 'lib/turkish_id.rb', line 7

def checksum
  @checksum
end

#elder_relativeObject (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_numberObject (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_relativeObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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