Class: CreditOfficer::MonthYearPair

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Base

#persisted?, #to_key, #to_model, #to_param

Constructor Details

#initialize(attrs = {}) ⇒ MonthYearPair

Returns a new instance of MonthYearPair.

Parameters:

  • hash (Hash)

    of attributes to set



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

#monthObject

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

#yearObject

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.

Returns:

  • (Boolean)

    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_monthTime?

Returns the last minute of the month in UTC or nil if an invalid pair was specified.

Returns:

  • (Time, nil)

    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.

Returns:



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.

Returns:

  • (Boolean)

    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_monthTime?

Returns the first minute of the month in UTC or nil if an invalid pair was specified.

Returns:

  • (Time, nil)

    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