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')
63 64 65 |
# File 'lib/simplepay/support/interval.rb', line 63 def initialize(*args) parse_arguments(*args) end |
Instance Attribute Details
#interval ⇒ Object
The interval, or “period”, of time
22 23 24 |
# File 'lib/simplepay/support/interval.rb', line 22 def interval @interval end |
#quantity ⇒ Object
The numeric number of intervals
19 20 21 |
# File 'lib/simplepay/support/interval.rb', line 19 def quantity @quantity end |
Class Method Details
.allowed_intervals ⇒ Object
27 28 29 |
# File 'lib/simplepay/support/interval.rb', line 27 def allowed_intervals const_get(:ALLOWED_INTERVALS) end |
.allowed_quantity_range ⇒ Object
31 32 33 |
# File 'lib/simplepay/support/interval.rb', line 31 def allowed_quantity_range const_get(:ALLOWED_QUANTITY_RANGE) end |
.default_interval ⇒ Object
39 40 41 |
# File 'lib/simplepay/support/interval.rb', line 39 def default_interval const_get(:DEFAULT_INTERVAL) end |
.default_quantity ⇒ Object
35 36 37 |
# File 'lib/simplepay/support/interval.rb', line 35 def default_quantity const_get(:DEFAULT_QUANTITY) end |
Instance Method Details
#allowed_intervals ⇒ Object
:nodoc:
92 93 94 |
# File 'lib/simplepay/support/interval.rb', line 92 def allowed_intervals #:nodoc: self.class.allowed_intervals end |
#allowed_quantity_range ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/simplepay/support/interval.rb', line 96 def allowed_quantity_range #:nodoc: self.class.allowed_quantity_range end |
#default_interval ⇒ Object
:nodoc:
104 105 106 |
# File 'lib/simplepay/support/interval.rb', line 104 def default_interval #:nodoc: self.class.default_interval end |
#default_quantity ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/simplepay/support/interval.rb', line 100 def default_quantity #:nodoc: self.class.default_quantity end |