Module: Deli::Param::Time

Included in:
Adapters::ActiveRecord::Time, Adapters::Cassandra::Time, Adapters::Mongoid::Time, Adapters::Neo4j::Time, Adapters::Simple::Time, Date
Defined in:
lib/deli/param.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) parse(value, as = :time)



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deli/param.rb', line 4

def parse(value, as = :time)
  values  = []
  
  value.to_s.split(/[\s,\+]/).each do |string|
    if string =~ /([^\.]+)?(\.\.)([^\.]+)?/
      starts_on, operator, ends_on = $1, $2, $3
      range   = []
      range   << parse_value(starts_on, [">="]) if !!(starts_on.present? && starts_on =~ /^\d/)
      range   << parse_value(ends_on, ["<="])   if !!(ends_on.present? && ends_on =~ /^\d/)
      values  << range
    else
      values  << [parse_value(string, ["="])]
    end
  end
  
  values
end

- (Object) parse_value(value, operators)



22
23
24
# File 'lib/deli/param.rb', line 22

def parse_value(value, operators)
  super(::Time.zone.parse(value), operators)
end