CloudSesame 0.7.10 → 0.7.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@ module CloudSesame
11
11
  RANGE_FORMAT = Regexp.new(/\A(\[|{)(.*),(.*)(\}|\])\z/).freeze
12
12
  DIGIT_FORMAT = Regexp.new(/\A\d+(.\d+)?\z/).freeze
13
13
  DATETIME_FORMAT = Regexp.new(/\d+{4}-\d+{2}-\d+{2}T\d+{2}:\d+{2}:\d+{2}/).freeze
14
+ TIME_FORMAT = Regexp.new(/\d+{4}-\d+{2}-\d+{2} \d+{2}:\d+{2}:\d+{2}/).freeze
14
15
  DATE_FORMAT = Regexp.new(/\d+{4}-\d+{2}-\d+{2}/).freeze
15
16
 
16
17
  attr_reader :value, :changed, :compiled
@@ -42,6 +43,10 @@ module CloudSesame
42
43
  value.is_a?(String) && DATETIME_FORMAT =~ value
43
44
  end
44
45
 
46
+ def self.string_time?(value)
47
+ value.is_a?(String) && TIME_FORMAT =~ value
48
+ end
49
+
45
50
  def self.string_date?(value)
46
51
  value.is_a?(String) && DATE_FORMAT =~ value
47
52
  end
@@ -5,15 +5,19 @@ module CloudSesame
5
5
 
6
6
  COMPILE_FORMAT = '%FT%TZ'.freeze
7
7
  DATETIME_FORMAT = '%FT%T'.freeze
8
+ TIME_FORMAT = '%F %T %z'.freeze
8
9
  DATE_FORMAT = '%F'.freeze
9
10
 
10
11
  def self.parse(value)
11
12
  return value.parse self if value.kind_of?(RangeValue)
13
+ range?(value) || string_range?(value) ? RangeValue.new(value, self) : new(value)
14
+ end
12
15
 
13
- range?(value) || string_range?(value) ? RangeValue.new(value, self) :
14
- string_datetime?(value) ? new(parse_datetime(value)) :
15
- string_date?(value) ? new(parse_date(value)) :
16
- new(value)
16
+ def initialize(value, type = nil)
17
+ value = Value.string_datetime?(value) ? parse_datetime(value) :
18
+ Value.string_time?(value) ? parse_time(value) :
19
+ Value.string_date?(value) ? parse_date(value) : value
20
+ super(value, type)
17
21
  end
18
22
 
19
23
  def to_s
@@ -22,11 +26,15 @@ module CloudSesame
22
26
 
23
27
  private
24
28
 
25
- def self.parse_datetime(string)
29
+ def parse_datetime(string)
26
30
  DateTime.strptime(string, DATETIME_FORMAT)
27
31
  end
28
32
 
29
- def self.parse_date(string)
33
+ def parse_time(string)
34
+ DateTime.strptime(string, TIME_FORMAT)
35
+ end
36
+
37
+ def parse_date(string)
30
38
  Date.strptime(string, DATE_FORMAT)
31
39
  end
32
40
 
@@ -86,7 +86,7 @@ module CloudSesame
86
86
  end
87
87
 
88
88
  def build_from_string(string)
89
- matches = RANGE_FORMAT.match(strip(string)).captures
89
+ matches = RANGE_FORMAT.match(string.strip).captures
90
90
  matches[1,2] = matches[1,2].map { |i| i unless i.empty? }
91
91
  initialize_value(*matches)
92
92
  end
@@ -18,7 +18,7 @@ module CloudSesame
18
18
  (
19
19
  range_value?(value) ? RangeValue :
20
20
  numeric_value?(value) ? NumericValue :
21
- datetime?(value) ? DateValue : StringValue
21
+ datetime_value?(value) ? DateValue : StringValue
22
22
  ).new(value, self)
23
23
  end
24
24
 
@@ -30,6 +30,10 @@ module CloudSesame
30
30
  numeric?(value) || string_numeric?(value)
31
31
  end
32
32
 
33
+ def self.datetime_value?(value)
34
+ datetime?(value) || string_datetime?(value) || string_time?(value)
35
+ end
36
+
33
37
  end
34
38
  end
35
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CloudSesame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.10
4
+ version: 0.7.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu