Class: Abaci::DateRange
- Inherits:
-
Object
- Object
- Abaci::DateRange
- Defined in:
- lib/abaci/date_range.rb
Instance Attribute Summary collapse
-
#finish ⇒ Object
readonly
Returns the value of attribute finish.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Class Method Summary collapse
Instance Method Summary collapse
- #days ⇒ Object
-
#initialize(start, finish) ⇒ DateRange
constructor
A new instance of DateRange.
- #keys ⇒ Object
- #range ⇒ Object
Constructor Details
#initialize(start, finish) ⇒ DateRange
Returns a new instance of DateRange.
5 6 7 8 9 10 11 12 13 |
# File 'lib/abaci/date_range.rb', line 5 def initialize(start, finish) if start < finish @start = start @finish = finish else @start = finish @finish = start end end |
Instance Attribute Details
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
3 4 5 |
# File 'lib/abaci/date_range.rb', line 3 def finish @finish end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
3 4 5 |
# File 'lib/abaci/date_range.rb', line 3 def start @start end |
Class Method Details
.ago(days = 30) ⇒ Object
27 28 29 30 31 |
# File 'lib/abaci/date_range.rb', line 27 def self.ago(days = 30) seconds = days.to_i * 86400 start = (Date.today - Rational(seconds, 86400)).to_date new(start, Date.today) end |
.between(start, finish) ⇒ Object
33 34 35 |
# File 'lib/abaci/date_range.rb', line 33 def self.between(start, finish) new(start, finish) end |
.since(date) ⇒ Object
37 38 39 |
# File 'lib/abaci/date_range.rb', line 37 def self.since(date) new(date, Date.today) end |
Instance Method Details
#days ⇒ Object
15 16 17 |
# File 'lib/abaci/date_range.rb', line 15 def days range.to_a end |
#keys ⇒ Object
19 20 21 |
# File 'lib/abaci/date_range.rb', line 19 def keys days.map { |d| d.strftime('%Y:%-m:%-d') } end |
#range ⇒ Object
23 24 25 |
# File 'lib/abaci/date_range.rb', line 23 def range start..finish end |