nickel 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.
- data/History.txt +4 -0
- data/README.rdoc +7 -1
- data/lib/nickel.rb +10 -4
- data/nickel.gemspec +1 -1
- data/test/nickel_spec.rb +15 -0
- metadata +3 -3
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
=== Nickel is a client for Natural Inputs
|
2
2
|
=== Install
|
3
3
|
|
4
|
-
gem install
|
4
|
+
gem install nickel
|
5
5
|
|
6
6
|
=== Usage
|
7
7
|
|
@@ -49,3 +49,9 @@
|
|
49
49
|
n.occurrences[1].type # => weekly
|
50
50
|
n.occurrences[1].day_of_week # => wed
|
51
51
|
n.occurrences[1].start_time # => 14:00:00
|
52
|
+
|
53
|
+
==== Setting current time
|
54
|
+
|
55
|
+
n = Nickel.query "lunch 3 days from now", DateTime.new(2010,3,31)
|
56
|
+
n.message # => lunch
|
57
|
+
n.occurrences[0].start_date # => 20100403
|
data/lib/nickel.rb
CHANGED
@@ -2,11 +2,11 @@ require 'rubygems'
|
|
2
2
|
require 'mapricot'
|
3
3
|
|
4
4
|
module Nickel
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.3"
|
6
6
|
|
7
|
-
def self.query(q)
|
8
|
-
|
9
|
-
url = "http://naturalinputs.com/query?q=#{URI.escape(q)}&t=#{
|
7
|
+
def self.query(q, current_time = Time.now)
|
8
|
+
raise InvalidDateTimeError unless [DateTime, Time].include?(current_time.class)
|
9
|
+
url = "http://naturalinputs.com/query?q=#{URI.escape(q)}&t=#{current_time.strftime("%Y%m%dT%H%M%S")}"
|
10
10
|
Mapricot.parser = :libxml
|
11
11
|
Api::NaturalInputsResponse.new(:url => url)
|
12
12
|
end
|
@@ -32,4 +32,10 @@ module Nickel
|
|
32
32
|
has_one :interval, :integer
|
33
33
|
end
|
34
34
|
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class InvalidDateTimeError < StandardError
|
38
|
+
def message
|
39
|
+
"You must pass in a ruby DateTime or Time class object"
|
40
|
+
end
|
35
41
|
end
|
data/nickel.gemspec
CHANGED
data/test/nickel_spec.rb
CHANGED
@@ -147,4 +147,19 @@ describe "Multiple occurrences" do
|
|
147
147
|
@n.occurrences[0].start_time.should == "14:00:00"
|
148
148
|
@n.occurrences[1].start_time.should == "14:00:00"
|
149
149
|
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "Setting current time" do
|
153
|
+
|
154
|
+
it "should occur on a date relative to the current time passed in" do
|
155
|
+
n = Nickel.query "lunch 3 days from now", DateTime.new(2009,05,28)
|
156
|
+
n.occurrences.first.start_date.should == "20090531"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should raise an error if the current time argument is not a datetime or time object" do
|
160
|
+
lambda{
|
161
|
+
Nickel.query "lunch 3 days from now", Date.new(2009,05,28)
|
162
|
+
}.should raise_error("You must pass in a ruby DateTime or Time class object")
|
163
|
+
end
|
164
|
+
|
150
165
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lou Zell
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-02 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|