Class: Identification::Document Abstract
- Inherits:
-
Object
- Object
- Identification::Document
- Defined in:
- lib/identification/document.rb
Overview
Subclass and implement a #parse method (setting the fields and @validity)
Represents an identity document. This class carries base methods that will appear in all document types.
and alter #initialize to implement a custom Document class. See other classes for examples.
Instance Attribute Summary collapse
-
#date_of_birth ⇒ Object
Returns the value of attribute date_of_birth.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
Instance Method Summary collapse
-
#age ⇒ Boolean
Returns the age of the individual.
-
#initialize(params = {}) ⇒ Document
constructor
Creates an instance of a documents.
-
#over_18? ⇒ Boolean
Returns true if the individual is over 18 (18+) Requires a date of birth to be set before it can be called.
-
#over_21? ⇒ Boolean
Returns true if the individual is over 21 (21+) Requires a date of birth to be set before it can be called.
-
#valid? ⇒ Boolean
Returns true if the drivers license is valid.
Constructor Details
#initialize(params = {}) ⇒ Document
Creates an instance of a documents. Will automatically parse if the drivers number is given, and will automatically generate if all necessary fields are set.
17 18 19 20 21 |
# File 'lib/identification/document.rb', line 17 def initialize(params = {}) @last_name = params[:last_name] @date_of_birth = params[:date_of_birth] @gender = params[:gender] end |
Instance Attribute Details
#date_of_birth ⇒ Object
Returns the value of attribute date_of_birth.
8 9 10 |
# File 'lib/identification/document.rb', line 8 def date_of_birth @date_of_birth end |
#gender ⇒ Object
Returns the value of attribute gender.
8 9 10 |
# File 'lib/identification/document.rb', line 8 def gender @gender end |
#last_name ⇒ Object
Returns the value of attribute last_name.
8 9 10 |
# File 'lib/identification/document.rb', line 8 def last_name @last_name end |
Instance Method Details
#age ⇒ Boolean
Returns the age of the individual. Requires a date of birth to be set before it can be called.
41 42 43 44 45 46 47 48 49 |
# File 'lib/identification/document.rb', line 41 def age if !@date_of_birth.nil? now = Time.now.utc.to_date dob = @date_of_birth return now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) else fail 'No date of birth has been set.' end end |
#over_18? ⇒ Boolean
Returns true if the individual is over 18 (18+) Requires a date of birth to be set before it can be called.
56 57 58 59 60 61 62 63 64 |
# File 'lib/identification/document.rb', line 56 def over_18? if !@date_of_birth.nil? return true if age >= 18 else fail 'No date of birth has been set.' end false end |
#over_21? ⇒ Boolean
Returns true if the individual is over 21 (21+) Requires a date of birth to be set before it can be called.
71 72 73 74 75 76 77 78 79 |
# File 'lib/identification/document.rb', line 71 def over_21? if !@date_of_birth.nil? return true if age >= 21 else fail 'No date of birth has been set.' end false end |
#valid? ⇒ Boolean
Returns true if the drivers license is valid. Requires the driver number to be parsed before it can be called.
28 29 30 31 32 33 34 |
# File 'lib/identification/document.rb', line 28 def valid? if defined? @validity return @validity else fail 'No document number has been parsed.' end end |