Class: Datesplit
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #end_date ⇒ Object
-
#initialize(date_string) ⇒ Datesplit
constructor
A new instance of Datesplit.
- #number_of_days ⇒ Object
- #range ⇒ Object
- #start_date ⇒ Object
Constructor Details
#initialize(date_string) ⇒ Datesplit
Returns a new instance of Datesplit.
4 5 6 |
# File 'lib/datesplit.rb', line 4 def initialize(date_string) @date_string = String.new(date_string) end |
Instance Method Details
#each(&blk) ⇒ Object
34 35 36 |
# File 'lib/datesplit.rb', line 34 def each(&blk) range.each(&blk) end |
#end_date ⇒ Object
12 13 14 |
# File 'lib/datesplit.rb', line 12 def end_date range.end end |
#number_of_days ⇒ Object
30 31 32 |
# File 'lib/datesplit.rb', line 30 def number_of_days range.to_a.size end |
#range ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/datesplit.rb', line 16 def range return if @range expressions.each do |expression, returns| m = @date_string.match(expression) if m @start = Date.parse("#{m.captures[returns.index(:month_only) || returns.index(:month_one)]} #{m.captures[returns.index(:day_one)]} #{m.captures[returns.index(:year_only) || returns.index(:year_one)]}") @end = Date.parse("#{m.captures[returns.index(:month_only) || returns.index(:month_two) ]} #{m.captures[returns.index(:day_two)]} #{m.captures[returns.index(:year_only) || returns.index(:year_two)]}") break end end raise "Can't process #{@date_string}" unless @start && @end @start..@end end |
#start_date ⇒ Object
8 9 10 |
# File 'lib/datesplit.rb', line 8 def start_date range.begin end |