Class: Simplepay::Support::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/simplepay/support/interval.rb

Direct Known Subclasses

BillingFrequency, SubscriptionPeriod

Constant Summary collapse

ALLOWED_QUANTITY_RANGE =

If set, limits the quantity to a value within this range

nil
ALLOWED_INTERVALS =

If set, limits the interval set to a value within this array

nil
DEFAULT_QUANTITY =

Sets the default quantity value for new instances

nil
DEFAULT_INTERVAL =

Sets the default interval value for new instances

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Interval

Creates an instance of the Interval. This can be called in one of several ways:

no arguments

Creates a new interval instance with default values.

one argument, string

Creates a new interval by parsing the given string to set both the quantity and interval. Must be formatted as: “3 day” (quantity, space, interval)

one argument, hash

Creates a new interval and populates it with the given :quantity and :interval. Uses defaults if not given.

two arguments

Creates a new interval with the first argument as the quantity, second argument as the interval.

Examples

All of these are equivalent:

Interval.new("3 day")
Interval.new({:quantity => 3, :interval => 'day'})
Interval.new(3, 'day')


63
64
65
# File 'lib/simplepay/support/interval.rb', line 63

def initialize(*args)
  parse_arguments(*args)
end

Instance Attribute Details

#intervalObject

The interval, or “period”, of time



22
23
24
# File 'lib/simplepay/support/interval.rb', line 22

def interval
  @interval
end

#quantityObject

The numeric number of intervals



19
20
21
# File 'lib/simplepay/support/interval.rb', line 19

def quantity
  @quantity
end

Class Method Details

.allowed_intervalsObject



27
28
29
# File 'lib/simplepay/support/interval.rb', line 27

def allowed_intervals
  const_get(:ALLOWED_INTERVALS)
end

.allowed_quantity_rangeObject



31
32
33
# File 'lib/simplepay/support/interval.rb', line 31

def allowed_quantity_range
  const_get(:ALLOWED_QUANTITY_RANGE)
end

.default_intervalObject



39
40
41
# File 'lib/simplepay/support/interval.rb', line 39

def default_interval
  const_get(:DEFAULT_INTERVAL)
end

.default_quantityObject



35
36
37
# File 'lib/simplepay/support/interval.rb', line 35

def default_quantity
  const_get(:DEFAULT_QUANTITY)
end

Instance Method Details

#allowed_intervalsObject

:nodoc:



92
93
94
# File 'lib/simplepay/support/interval.rb', line 92

def allowed_intervals #:nodoc:
  self.class.allowed_intervals
end

#allowed_quantity_rangeObject

:nodoc:



96
97
98
# File 'lib/simplepay/support/interval.rb', line 96

def allowed_quantity_range #:nodoc:
  self.class.allowed_quantity_range
end

#default_intervalObject

:nodoc:



104
105
106
# File 'lib/simplepay/support/interval.rb', line 104

def default_interval #:nodoc:
  self.class.default_interval
end

#default_quantityObject

:nodoc:



100
101
102
# File 'lib/simplepay/support/interval.rb', line 100

def default_quantity #:nodoc:
  self.class.default_quantity
end

#to_sObject

Converts the interval into an Amazon-ready string.

Interval.new(3, 'day').to_s # => "3 day"


88
89
90
# File 'lib/simplepay/support/interval.rb', line 88

def to_s
  "#{quantity} #{interval}" if interval
end