Class: Personnummer::Born
- Inherits:
-
Object
- Object
- Personnummer::Born
- Defined in:
- lib/personnummer.rb
Instance Attribute Summary collapse
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #age ⇒ Object
- #co_ordination_number? ⇒ Boolean
- #day ⇒ Object
-
#initialize(century, year, month, day, divider) ⇒ Born
constructor
A new instance of Born.
- #to_date ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(century, year, month, day, divider) ⇒ Born
Returns a new instance of Born.
161 162 163 164 165 166 |
# File 'lib/personnummer.rb', line 161 def initialize(century, year, month, day, divider) @divider = divider @day = day @month = month @year = calculate_century(century, year) + year end |
Instance Attribute Details
#month ⇒ Object (readonly)
Returns the value of attribute month.
159 160 161 |
# File 'lib/personnummer.rb', line 159 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
159 160 161 |
# File 'lib/personnummer.rb', line 159 def year @year end |
Instance Method Details
#age ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/personnummer.rb', line 184 def age if Date.today > to_date (Date.today - to_date).to_i/365 else 0 end end |
#co_ordination_number? ⇒ Boolean
172 173 174 |
# File 'lib/personnummer.rb', line 172 def co_ordination_number? @day && 60 < @day and @day < 92 end |
#day ⇒ Object
168 169 170 |
# File 'lib/personnummer.rb', line 168 def day co_ordination_number? ? @day - 60 : @day end |
#to_date ⇒ Object
176 177 178 |
# File 'lib/personnummer.rb', line 176 def to_date Date.parse("#{year}-#{month}-#{day}") end |
#valid? ⇒ Boolean
180 181 182 |
# File 'lib/personnummer.rb', line 180 def valid? to_date && true end |