Class Simplepay::Support::Interval
In: lib/simplepay/support/interval.rb
Parent: Object
RuntimeError Error Service Standard Marketplace Donation Subscription MarketplacePolicy Interval SubscriptionPeriod BillingFrequency Comparable Field Service Epoch Currency Amount Boolean ResponseStatusCode Services Authentication FormHelper NotificationHelper RailsHelper Helpers Interval Currency Support Boolean Simplepay dot/f_2.png

Methods

Constants

ALLOWED_QUANTITY_RANGE = nil   If set, limits the quantity to a value within this range
ALLOWED_INTERVALS = nil   If set, limits the interval set to a value within this array
DEFAULT_QUANTITY = nil   Sets the default quantity value for new instances
DEFAULT_INTERVAL = nil   Sets the default interval value for new instances

Attributes

interval  [R]  The interval, or "period", of time
quantity  [R]  The numeric number of intervals

Public Class methods

[Source]

# File lib/simplepay/support/interval.rb, line 27
        def allowed_intervals
          const_get(:ALLOWED_INTERVALS)
        end

[Source]

# File lib/simplepay/support/interval.rb, line 31
        def allowed_quantity_range
          const_get(:ALLOWED_QUANTITY_RANGE)
        end

[Source]

# File lib/simplepay/support/interval.rb, line 39
        def default_interval
          const_get(:DEFAULT_INTERVAL)
        end

[Source]

# File lib/simplepay/support/interval.rb, line 35
        def default_quantity
          const_get(:DEFAULT_QUANTITY)
        end

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

[Source]

# File lib/simplepay/support/interval.rb, line 63
      def initialize(*args)
        parse_arguments(*args)
      end

Public Instance methods

Set the interval.

[Source]

# File lib/simplepay/support/interval.rb, line 70
      def interval=(i)
        raise(ArgumentError, "Interval '#{i}' should be one of: #{allowed_intervals.join(', ')}") if i && allowed_intervals && !allowed_intervals.include?(i)
        @interval = i
      end

Set the quantity.

[Source]

# File lib/simplepay/support/interval.rb, line 78
      def quantity=(q)
        raise(ArgumentError, "Quantity '#{q}' should be in #{allowed_quantity_range}") if q && allowed_quantity_range && !allowed_quantity_range.include?(q)
        @quantity = q
      end

Converts the interval into an Amazon-ready string.

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

[Source]

# File lib/simplepay/support/interval.rb, line 88
      def to_s
        "#{quantity} #{interval}" if interval
      end

[Validate]