date_interval 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50fe6f00cdc14871f25bf3ebd95be0fd146b8403
4
- data.tar.gz: c63993f601f26eeddaf989e72a27cad8f77a5910
3
+ metadata.gz: d152db4e7865cac25d7a2b1b08d2cc80bbe8eb20
4
+ data.tar.gz: b5e555298cd3a97e4fe67896d0d2453e2f7f7829
5
5
  SHA512:
6
- metadata.gz: f9f1302693ed944c6c3c6d043d56ce6813878e8b1a45309df1dc11b083d7673a824cb7a73aad80b64337d158fff353f3241b8447161cf1eef39bf7c14e054e78
7
- data.tar.gz: 4a9acc94cd65932d63f8769bc8c838e62b4800f5f1a16c715fd4a80aec9fbeb772d2cb5d34d6149ea4c03ea366a185298651b2d0c9de9c55e4e3d66b76850bc4
6
+ metadata.gz: 1a9d2410b4bf99186e5c19537f21e28fce8e30628a9e748cba412af0fb37c3de5a863bb49b3453f9051f9d1b984c05c8a123627e6ac6e9727e8091b8ea801890
7
+ data.tar.gz: bea237b30f2c170ece7b345e74b2bb5eacdc7bb5a70a0194b6ed422f829a8173b27b99c6fc81f3c2c0ef5905d71d822bae5ee50a3048bdc1b6baabffb81dbde4
data/README.md CHANGED
@@ -97,9 +97,23 @@ DateInterval.parse("2014-01-01 - 2014-12-31, none, +holidays")
97
97
  # ]
98
98
  ```
99
99
 
100
+ ### Validating expressions
101
+
102
+ To validation if an expression is valid use the `DateInterval.valid?` method.
103
+
104
+ ```ruby
105
+ require "date_interval"
106
+
107
+ DateInterval.valid?("2014-01-01 - 2014-01-05")
108
+ #=> true
109
+
110
+ DateInterval.valid?("invalid")
111
+ #=> false
112
+ ```
113
+
100
114
  ## Contributing
101
115
 
102
- 1. Fork it ( http://github.com/[my-github-username]/date_interval/fork )
116
+ 1. Fork it ( http://github.com/fnando/date_interval/fork )
103
117
  2. Create your feature branch (`git checkout -b my-new-feature`)
104
118
  3. Commit your changes (`git commit -am 'Add some feature'`)
105
119
  4. Push to the branch (`git push origin my-new-feature`)
@@ -19,9 +19,6 @@ module DateInterval
19
19
  InvalidRuleError = Class.new(StandardError)
20
20
 
21
21
  def self.parse(expression)
22
- parser = Parser.new
23
- transformer = Transformer.new
24
-
25
22
  tree = parser.parse(expression)
26
23
  ast = transformer.apply(tree)
27
24
 
@@ -30,4 +27,20 @@ module DateInterval
30
27
  ast[:filters].kind_of?(Array) ? ast[:filters] : []
31
28
  )
32
29
  end
30
+
31
+ def self.valid?(expression)
32
+ parser.parse(expression)
33
+ return true
34
+ rescue Parslet::ParseFailed
35
+ return false
36
+ end
37
+
38
+ private
39
+ def self.parser
40
+ Parser.new
41
+ end
42
+
43
+ def self.transformer
44
+ Transformer.new
45
+ end
33
46
  end
@@ -1,3 +1,3 @@
1
1
  module DateInterval
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -191,4 +191,12 @@ describe DateInterval do
191
191
 
192
192
  expect(interval).to eql(expected_interval)
193
193
  end
194
+
195
+ it "detects expression as valid" do
196
+ expect(DateInterval).to be_valid("2014-01-01 - 2014-01-02")
197
+ end
198
+
199
+ it "detects expression as invalid" do
200
+ expect(DateInterval).not_to be_valid("invalid")
201
+ end
194
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_interval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira