Class: AhlScraper::BirthdateHelper
- Inherits:
-
Object
- Object
- AhlScraper::BirthdateHelper
- Defined in:
- lib/ahl_scraper/helpers/birthdate_helper.rb
Instance Attribute Summary collapse
-
#birthdate ⇒ Object
readonly
Returns the value of attribute birthdate.
Instance Method Summary collapse
- #age_on_date(date, round: 2) ⇒ Object
- #current_age(round: 2) ⇒ Object
- #draft_year ⇒ Object
-
#initialize(birthdate) ⇒ BirthdateHelper
constructor
A new instance of BirthdateHelper.
Constructor Details
#initialize(birthdate) ⇒ BirthdateHelper
Returns a new instance of BirthdateHelper.
9 10 11 |
# File 'lib/ahl_scraper/helpers/birthdate_helper.rb', line 9 def initialize(birthdate) @birthdate = Date.parse(birthdate) end |
Instance Attribute Details
#birthdate ⇒ Object (readonly)
Returns the value of attribute birthdate.
7 8 9 |
# File 'lib/ahl_scraper/helpers/birthdate_helper.rb', line 7 def birthdate @birthdate end |
Instance Method Details
#age_on_date(date, round: 2) ⇒ Object
23 24 25 |
# File 'lib/ahl_scraper/helpers/birthdate_helper.rb', line 23 def age_on_date(date, round: 2) ((Date.parse(date).to_datetime - birthdate.to_datetime).to_i / BigDecimal("365")).round(round) end |
#current_age(round: 2) ⇒ Object
19 20 21 |
# File 'lib/ahl_scraper/helpers/birthdate_helper.rb', line 19 def current_age(round: 2) ((Time.now.utc.to_datetime - birthdate.to_datetime).to_i / BigDecimal("365")).round(round) end |
#draft_year ⇒ Object
13 14 15 16 17 |
# File 'lib/ahl_scraper/helpers/birthdate_helper.rb', line 13 def draft_year return (birthdate + (19 * 365)).year if (birthdate.month == 9 && birthdate.day > 15) || birthdate.month > 9 (birthdate + (18 * 365)).year end |