Class: Cfita::CodiceFiscale

Inherits:
Object
  • Object
show all
Defined in:
lib/cfita/codice_fiscale.rb

Overview

Controllo codice fiscale italiano

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fiscal_code, birth_place: nil, birth_date: nil, name: nil, surname: nil, sex: nil) ⇒ CodiceFiscale

Returns a new instance of CodiceFiscale.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cfita/codice_fiscale.rb', line 19

def initialize(
  fiscal_code,
  birth_place: nil,
  birth_date: nil,
  name: nil,
  surname: nil,
  sex: nil
)
  @fiscal_code = fiscal_code.upcase.strip
  @birth_place = birth_place&.upcase
  @birth_date = birth_date
  @birth_date = Date.parse(birth_date) if birth_date.is_a?(String)
  @name = name&.parameterize&.upcase
  @surname = surname&.parameterize&.upcase
  @sex = sex&.upcase
  @errors = []
  parse
end

Instance Attribute Details

#birth_dateObject (readonly)

Returns the value of attribute birth_date.



9
10
11
# File 'lib/cfita/codice_fiscale.rb', line 9

def birth_date
  @birth_date
end

#birth_placeObject (readonly)

Returns the value of attribute birth_place.



9
10
11
# File 'lib/cfita/codice_fiscale.rb', line 9

def birth_place
  @birth_place
end

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/cfita/codice_fiscale.rb', line 9

def errors
  @errors
end

#fiscal_codeObject (readonly)

Returns the value of attribute fiscal_code.



9
10
11
# File 'lib/cfita/codice_fiscale.rb', line 9

def fiscal_code
  @fiscal_code
end

#sexObject (readonly)

Returns the value of attribute sex.



9
10
11
# File 'lib/cfita/codice_fiscale.rb', line 9

def sex
  @sex
end

Class Method Details

.ccatObject



15
16
17
# File 'lib/cfita/codice_fiscale.rb', line 15

def self.ccat
  @ccat ||= JSON.parse(open('ccat.json'))
end

Instance Method Details

#to_sObject



38
39
40
# File 'lib/cfita/codice_fiscale.rb', line 38

def to_s
  fiscal_code
end

#valid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/cfita/codice_fiscale.rb', line 42

def valid?
  errors.empty?
end