Class: Monthly::Splitter
- Inherits:
-
Object
- Object
- Monthly::Splitter
- Defined in:
- lib/monthly/splitter.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(from, to) ⇒ Splitter
constructor
A new instance of Splitter.
Constructor Details
#initialize(from, to) ⇒ Splitter
5 6 7 8 9 |
# File 'lib/monthly/splitter.rb', line 5 def initialize(from, to) @from, @to = from, to @current_from = self.from @current_to = last_day_of_month(self.from) end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/monthly/splitter.rb', line 3 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
3 4 5 |
# File 'lib/monthly/splitter.rb', line 3 def to @to end |
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/monthly/splitter.rb', line 11 def execute [].tap do |out| out << {from: self.from, to: self.to} if out_of_range?(@current_to) while in_range?(@current_to) out << {from: @current_from, to: @current_to} out << {from: next_from, to: self.to} if last_month_is_partial? set_next_from_and_to end end end |