Class: Rupee::Frequency
- Inherits:
-
Object
- Object
- Rupee::Frequency
- Defined in:
- lib/rupee/frequency.rb
Overview
A frequency
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
The amount of units.
-
#unit ⇒ Object
readonly
The units in which to count (
:days
,:months
,:years
, etc..
Instance Method Summary collapse
- #build(from, to) ⇒ Object
-
#initialize(amount, unit) ⇒ Frequency
constructor
Creates a new frequency object.
Constructor Details
#initialize(amount, unit) ⇒ Frequency
Creates a new frequency object
11 12 13 14 |
# File 'lib/rupee/frequency.rb', line 11 def initialize(amount, unit) @amount = amount @unit = unit end |
Instance Attribute Details
#amount ⇒ Object (readonly)
The amount of units
5 6 7 |
# File 'lib/rupee/frequency.rb', line 5 def amount @amount end |
#unit ⇒ Object (readonly)
The units in which to count (:days
, :months
, :years
, etc.
8 9 10 |
# File 'lib/rupee/frequency.rb', line 8 def unit @unit end |
Instance Method Details
#build(from, to) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rupee/frequency.rb', line 16 def build(from, to) results = [] temp = from multiplier = 1 case @unit when :day, :days while temp < to temp += @amount results << temp end when :week, :weeks while temp < to temp += @amount * 7 results << temp end when :month, :months while temp < to temp = from.next_month(@amount * multiplier) multiplier += 1 results << temp end when :year, :years while temp < to temp = from.next_year(@amount * multiplier) multiplier += 1 results << temp end end results end |