Class: CreditOfficer::MonthYearPair
- Defined in:
- lib/credit_officer/month_year_pair.rb
Overview
ActiveModel compliant abstraction representing the month/year pairs often found on credit cards
For most, the only one found on the front is an expiration date
For switch and solo cards, an additional start date might be specified
Constant Summary collapse
- RECENT_FUTURE_YEAR_LIMIT =
20
Instance Attribute Summary collapse
-
#month ⇒ Object
- Integer
-
the numberic representation of the month (1-12) (required for validity).
-
#year ⇒ Object
- Integer
-
the year (required for validity).
Instance Method Summary collapse
-
#end_is_in_past? ⇒ Boolean
Whether the last minute of the month is in the past.
-
#end_of_month ⇒ Time?
The last minute of the month in UTC or nil if an invalid pair was specified.
-
#exceeds_recent_future? ⇒ Boolean
Whether the last minute of the month is within the bound of RECENT_FUTURE_YEAR_LIMIT.
-
#initialize(attrs = {}) ⇒ MonthYearPair
constructor
A new instance of MonthYearPair.
-
#start_is_in_future? ⇒ Boolean
Whether the first minute of the month is in the future.
-
#start_of_month ⇒ Time?
The first minute of the month in UTC or nil if an invalid pair was specified.
Methods inherited from Base
#persisted?, #to_key, #to_model, #to_param
Constructor Details
#initialize(attrs = {}) ⇒ MonthYearPair
Returns a new instance of MonthYearPair.
22 23 24 25 |
# File 'lib/credit_officer/month_year_pair.rb', line 22 def initialize(attrs = {}) self.year = attrs[:year].to_i self.month = attrs[:month].to_i end |
Instance Attribute Details
#month ⇒ Object
- Integer
-
the numberic representation of the month (1-12) (required for validity)
14 15 16 |
# File 'lib/credit_officer/month_year_pair.rb', line 14 def month @month end |
#year ⇒ Object
- Integer
-
the year (required for validity)
11 12 13 |
# File 'lib/credit_officer/month_year_pair.rb', line 11 def year @year end |
Instance Method Details
#end_is_in_past? ⇒ Boolean
Returns whether the last minute of the month is in the past.
28 29 30 |
# File 'lib/credit_officer/month_year_pair.rb', line 28 def end_is_in_past? #:nodoc: Time.now.utc > end_of_month end |
#end_of_month ⇒ Time?
Returns the last minute of the month in UTC or nil if an invalid pair was specified.
54 55 56 57 58 59 60 |
# File 'lib/credit_officer/month_year_pair.rb', line 54 def end_of_month begin Time.utc(year, month, Time.days_in_month(month, year), 23, 59, 59) rescue ArgumentError nil end end |
#exceeds_recent_future? ⇒ Boolean
Returns whether the last minute of the month is within the bound of RECENT_FUTURE_YEAR_LIMIT.
40 41 42 |
# File 'lib/credit_officer/month_year_pair.rb', line 40 def exceeds_recent_future? end_of_month >= Time.now.utc.advance(:years => RECENT_FUTURE_YEAR_LIMIT) end |
#start_is_in_future? ⇒ Boolean
Returns whether the first minute of the month is in the future.
33 34 35 |
# File 'lib/credit_officer/month_year_pair.rb', line 33 def start_is_in_future? Time.now.utc < start_of_month end |
#start_of_month ⇒ Time?
Returns the first minute of the month in UTC or nil if an invalid pair was specified.
45 46 47 48 49 50 51 |
# File 'lib/credit_officer/month_year_pair.rb', line 45 def start_of_month begin Time.utc(year, month, 1, 0, 0, 1) rescue ArgumentError nil end end |