Class: Simplepay::Support::Interval
- Inherits:
-
Object
- Object
- Simplepay::Support::Interval
- Defined in:
- lib/simplepay/support/interval.rb
Direct Known Subclasses
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
-
#interval ⇒ Object
The interval, or “period”, of time.
-
#quantity ⇒ Object
The numeric number of intervals.
Class Method Summary collapse
- .allowed_intervals ⇒ Object
- .allowed_quantity_range ⇒ Object
- .default_interval ⇒ Object
- .default_quantity ⇒ Object
Instance Method Summary collapse
-
#allowed_intervals ⇒ Object
:nodoc:.
-
#allowed_quantity_range ⇒ Object
:nodoc:.
-
#default_interval ⇒ Object
:nodoc:.
-
#default_quantity ⇒ Object
:nodoc:.
-
#initialize(*args) ⇒ Interval
constructor
Creates an instance of the Interval.
-
#to_s ⇒ Object
Converts the interval into an Amazon-ready string.
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
#interval ⇒ Object
The interval, or “period”, of time
24 25 26 |
# File 'lib/simplepay/support/interval.rb', line 24 def interval @interval end |
#quantity ⇒ Object
The numeric number of intervals
21 22 23 |
# File 'lib/simplepay/support/interval.rb', line 21 def quantity @quantity end |
Class Method Details
.allowed_intervals ⇒ Object
29 30 31 |
# File 'lib/simplepay/support/interval.rb', line 29 def allowed_intervals const_get(:ALLOWED_INTERVALS) end |
.allowed_quantity_range ⇒ Object
33 34 35 |
# File 'lib/simplepay/support/interval.rb', line 33 def allowed_quantity_range const_get(:ALLOWED_QUANTITY_RANGE) end |
.default_interval ⇒ Object
41 42 43 |
# File 'lib/simplepay/support/interval.rb', line 41 def default_interval const_get(:DEFAULT_INTERVAL) end |
.default_quantity ⇒ Object
37 38 39 |
# File 'lib/simplepay/support/interval.rb', line 37 def default_quantity const_get(:DEFAULT_QUANTITY) end |
Instance Method Details
#allowed_intervals ⇒ Object
:nodoc:
94 95 96 |
# File 'lib/simplepay/support/interval.rb', line 94 def allowed_intervals #:nodoc: self.class.allowed_intervals end |
#allowed_quantity_range ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/simplepay/support/interval.rb', line 98 def allowed_quantity_range #:nodoc: self.class.allowed_quantity_range end |
#default_interval ⇒ Object
:nodoc:
106 107 108 |
# File 'lib/simplepay/support/interval.rb', line 106 def default_interval #:nodoc: self.class.default_interval end |
#default_quantity ⇒ Object
:nodoc:
102 103 104 |
# File 'lib/simplepay/support/interval.rb', line 102 def default_quantity #:nodoc: self.class.default_quantity end |