Class: ChronicBetween
- Inherits:
-
Object
- Object
- ChronicBetween
- Includes:
- AppRoutes
- Defined in:
- lib/chronic_between.rb
Instance Method Summary collapse
-
#initialize(x) ⇒ ChronicBetween
constructor
A new instance of ChronicBetween.
- #within?(raw_date) ⇒ Boolean
Constructor Details
#initialize(x) ⇒ ChronicBetween
Returns a new instance of ChronicBetween.
13 14 15 16 17 18 |
# File 'lib/chronic_between.rb', line 13 def initialize(x) @times = x.is_a?(String) ? x.split(/[,;&]/).map(&:strip) : x puts '@times : ' + @times.inspect @routes = {}; @params = {} end |
Instance Method Details
#within?(raw_date) ⇒ Boolean
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 48 |
# File 'lib/chronic_between.rb', line 20 def within?(raw_date) date = raw_date.respond_to? ? :to_datetime : raw_date dates = [] ranges(@params, date) negatives = '(not|except)\s+' times, closed_times = @times.partition {|x| !x[/^#{negatives}/]} closed_times.map!{|x| x[/^#{negatives}(.*)/,2]} dates = build times puts 'dates : ' + dates.inspect inside_range = dates.detect {|d1, d2| p [d1,d2]; date.between? d1, d2} neg_dates = build closed_times inside_restrictions = neg_dates.detect {|d1, d2| date.between? d1, d2} if inside_restrictions then return false elsif closed_times.any? and times.empty? then return true elsif inside_range then return true else return false end end |