-
Notifications
You must be signed in to change notification settings - Fork 152
/
indexes.rb
89 lines (82 loc) · 1.57 KB
/
indexes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'tzinfo'
require 'active_support/core_ext/date/conversions'
require 'active_support/core_ext/date/zones'
require 'active_support/core_ext/date_time/conversions'
require 'active_support/core_ext/date_time/zones'
require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/time/zones'
require 'active_support/core_ext/string/conversions'
require 'ripple/property_type_mismatch'
require 'set'
# @private
class Object
def to_ripple_index(type)
case type
when 'bin'
to_s
when 'int'
to_i
end
end
end
# @private
class Time
def to_ripple_index(type)
case type
when 'bin'
utc.send(Ripple.date_format)
when 'int'
# Use millisecond-precision
(utc.to_f * 1000).round
end
end
end
# @private
class Date
def to_ripple_index(type)
case type
when 'bin'
to_s(Ripple.date_format)
when 'int'
to_time(:utc).to_ripple_index(type)
end
end
end
# @private
class DateTime
def to_ripple_index(type)
case type
when 'bin'
utc.to_s(Ripple.date_format)
when 'int'
(utc.to_f * 1000).round
end
end
end
# @private
module ActiveSupport
class TimeWithZone
def to_ripple_index(type)
utc.to_ripple_index(type)
end
end
end
# @private
module Enumerable
def to_ripple_index(type)
Set.new(map {|v| v.to_ripple_index(type) })
end
end
if String < Enumerable
# Fix for 1.8, in which String is Enumerable
class String
def to_ripple_index(type)
case type
when 'bin'
to_s
when 'int'
to_i
end
end
end
end