Class: Personnummer::Born

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#monthObject (readonly)

Returns the value of attribute month.



159
160
161
# File 'lib/personnummer.rb', line 159

def month
  @month
end

#yearObject (readonly)

Returns the value of attribute year.



159
160
161
# File 'lib/personnummer.rb', line 159

def year
  @year
end

Instance Method Details

#ageObject



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

Returns:

  • (Boolean)


172
173
174
# File 'lib/personnummer.rb', line 172

def co_ordination_number?
  @day && 60 < @day and @day < 92
end

#dayObject



168
169
170
# File 'lib/personnummer.rb', line 168

def day
  co_ordination_number? ? @day - 60 : @day
end

#to_dateObject



176
177
178
# File 'lib/personnummer.rb', line 176

def to_date
  Date.parse("#{year}-#{month}-#{day}")
end

#valid?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/personnummer.rb', line 180

def valid?
  to_date && true
end