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')


65
66
67
# File 'lib/simplepay/support/interval.rb', line 65

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

Instance Attribute Details

#intervalObject

The interval, or “period”, of time



24
25
26
# File 'lib/simplepay/support/interval.rb', line 24

def interval
  @interval
end

#quantityObject

The numeric number of intervals



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

def quantity
  @quantity
end

Class Method Details

.allowed_intervalsObject



29
30
31
# File 'lib/simplepay/support/interval.rb', line 29

def allowed_intervals
  const_get(:ALLOWED_INTERVALS)
end

.allowed_quantity_rangeObject



33
34
35
# File 'lib/simplepay/support/interval.rb', line 33

def allowed_quantity_range
  const_get(:ALLOWED_QUANTITY_RANGE)
end

.default_intervalObject



41
42
43
# File 'lib/simplepay/support/interval.rb', line 41

def default_interval
  const_get(:DEFAULT_INTERVAL)
end

.default_quantityObject



37
38
39
# File 'lib/simplepay/support/interval.rb', line 37

def default_quantity
  const_get(:DEFAULT_QUANTITY)
end

Instance Method Details

#allowed_intervalsObject

:nodoc:



94
95
96
# File 'lib/simplepay/support/interval.rb', line 94

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

#allowed_quantity_rangeObject

:nodoc:



98
99
100
# File 'lib/simplepay/support/interval.rb', line 98

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

#default_intervalObject

:nodoc:



106
107
108
# File 'lib/simplepay/support/interval.rb', line 106

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

#default_quantityObject

:nodoc:



102
103
104
# File 'lib/simplepay/support/interval.rb', line 102

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"


90
91
92
# File 'lib/simplepay/support/interval.rb', line 90

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