Class: Cfita::CodiceFiscale
- Inherits:
-
Object
- Object
- Cfita::CodiceFiscale
- Defined in:
- lib/cfita/codice_fiscale.rb
Overview
Controllo codice fiscale italiano
Instance Attribute Summary collapse
-
#birth_date ⇒ Object
readonly
Returns the value of attribute birth_date.
-
#birth_place ⇒ Object
readonly
Returns the value of attribute birth_place.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fiscal_code ⇒ Object
readonly
Returns the value of attribute fiscal_code.
-
#sex ⇒ Object
readonly
Returns the value of attribute sex.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fiscal_code, birth_place: nil, birth_date: nil, name: nil, surname: nil, sex: nil) ⇒ CodiceFiscale
constructor
A new instance of CodiceFiscale.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
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_date ⇒ Object (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_place ⇒ Object (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 |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/cfita/codice_fiscale.rb', line 9 def errors @errors end |
#fiscal_code ⇒ Object (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 |
#sex ⇒ Object (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
.ccat ⇒ Object
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_s ⇒ Object
38 39 40 |
# File 'lib/cfita/codice_fiscale.rb', line 38 def to_s fiscal_code end |
#valid? ⇒ Boolean
42 43 44 |
# File 'lib/cfita/codice_fiscale.rb', line 42 def valid? errors.empty? end |