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 CHANGED
@@ -5,3 +5,7 @@ Initial release!
5
5
  == 0.0.2 2009-03-30
6
6
 
7
7
  No www in request
8
+
9
+ == 0.0.3 2010-04-02
10
+
11
+ Able to set current time for query
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 lzell-nickel
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.2"
5
+ VERSION = "0.0.3"
6
6
 
7
- def self.query(q)
8
- date_time = Time.now.strftime("%Y%m%dT%H%M%S")
9
- url = "http://naturalinputs.com/query?q=#{URI.escape(q)}&t=#{date_time}"
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nickel"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "Natural language date and time parsing"
5
5
  s.email = "lzell11@gmail.com"
6
6
  s.homepage = "http://github.com/lzell/nickel"
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
- - 2
9
- version: 0.0.2
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-03-31 00:00:00 -04:00
17
+ date: 2010-04-02 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency