class CreditOfficer::MonthYearPair

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

Constants

RECENT_FUTURE_YEAR_LIMIT

Attributes

month[RW]
Integer

the numberic representation of the month (1-12) (required for validity)

year[RW]
Integer

the year (required for validity)

Public Class Methods

new(attrs = {}) click to toggle source

@param [Hash] hash of attributes to set

# 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

Public Instance Methods

end_of_month() click to toggle source

@return [Time, nil] the last minute of the month in UTC or nil if an invalid pair was specified

# 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?() click to toggle source

@return [Boolean] whether the last minute of the month is within the bound of {RECENT_FUTURE_YEAR_LIMIT}

# 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?() click to toggle source

@return [Boolean] whether the first minute of the month is in the future

# 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() click to toggle source

@return [Time, nil] the first minute of the month in UTC or nil if an invalid pair was specified

# 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