nickel 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ == 0.0.1 2009-03-22
2
+
3
+ Initial release!
4
+
5
+ == 0.0.2 2009-03-30
6
+
7
+ No www in request
data/License.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Louis Zell <lzell11@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ === Nickel is a client for Natural Inputs
2
+ === Install
3
+
4
+ gem install lzell-nickel
5
+
6
+ === Usage
7
+
8
+ ==== A single occurrence
9
+ n = Nickel.query "lunch tomorrow with maria"
10
+ n.message # => lunch with maria
11
+ n.occurrences[0].type # => single
12
+ n.occurrences[0].start_date # => 20090323
13
+
14
+ ==== A daily occurrence
15
+ n = Nickel.query "wake up everyday at 11am"
16
+ n.message # => wake up
17
+ n.occurrences[0].type # => daily
18
+ n.occurrences[0].start_time # => 11:00:00
19
+
20
+ ==== A weekly occurrence
21
+ n = Nickel.query "guitar lessons every tuesday at 5pm"
22
+ n.message # => guitar lessons
23
+ n.occurrences[0].type # => weekly
24
+ n.occurrences[0].day_of_week # => tue
25
+ n.occurrences[0].interval # => 1
26
+ n.occurrences[0].start_time # => 17:00:00
27
+
28
+ ==== A day monthly occurrence
29
+ n = Nickel.query "drink specials on the second thursday of every month"
30
+ n.message # => drink specials
31
+ n.occurrences[0].type # => daymonthly
32
+ n.occurrences[0].day_of_week # => thu
33
+ n.occurrences[0].week_of_month # => 2
34
+ n.occurrences[0].interval # => 1
35
+
36
+ ==== A date monthly occurrence
37
+ n = Nickel.query "pay credit card every month on the 22nd"
38
+ n.message # => pay credit card
39
+ n.occurrences[0].type # => datemonthly
40
+ n.occurrences[0].date_of_month # => 22
41
+ n.occurrences[0].interval # => 1
42
+
43
+ ==== Multiple occurrences
44
+ n = Nickel.query "band meeting every monday and wednesday at 2pm"
45
+ n.message # => band meeting
46
+ n.occurrences[0].type # => weekly
47
+ n.occurrences[0].day_of_week # => mon
48
+ n.occurrences[0].start_time # => 14:00:00
49
+ n.occurrences[1].type # => weekly
50
+ n.occurrences[1].day_of_week # => wed
51
+ n.occurrences[1].start_time # => 14:00:00
data/lib/nickel.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'mapricot'
3
+
4
+ module Nickel
5
+ VERSION = "0.0.2"
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}"
10
+ Mapricot.parser = :libxml
11
+ Api::NaturalInputsResponse.new(:url => url)
12
+ end
13
+ end
14
+
15
+
16
+ module Nickel
17
+ module Api
18
+ class NaturalInputsResponse < Mapricot::Base
19
+ has_one :message
20
+ has_many :occurrences, :xml
21
+ end
22
+
23
+ class Occurrence < Mapricot::Base
24
+ has_one :type
25
+ has_one :start_date
26
+ has_one :end_date
27
+ has_one :start_time
28
+ has_one :end_time
29
+ has_one :day_of_week
30
+ has_one :week_of_month, :integer
31
+ has_one :date_of_month, :integer
32
+ has_one :interval, :integer
33
+ end
34
+ end
35
+ end
data/nickel.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "nickel"
3
+ s.version = "0.0.2"
4
+ s.summary = "Natural language date and time parsing"
5
+ s.email = "lzell11@gmail.com"
6
+ s.homepage = "http://github.com/lzell/nickel"
7
+ s.description = "A client for naturalinputs.com. Extracts date, time, and message information from naturally worded text."
8
+ s.has_rdoc = true
9
+ s.authors = ["Lou Zell"]
10
+ s.files = ["README.rdoc",
11
+ "History.txt",
12
+ "License.txt",
13
+ "nickel.gemspec",
14
+ "test/nickel_spec.rb",
15
+ "lib/nickel.rb"]
16
+ s.require_paths = ["lib"]
17
+ s.rdoc_options = ["--main", "README.rdoc", "--title", "Nickel"]
18
+ s.extra_rdoc_files = ["README.rdoc"]
19
+ s.add_dependency("mapricot")
20
+ end
@@ -0,0 +1,150 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/nickel")
4
+
5
+
6
+ describe "A single date" do
7
+ before(:all) { @n = Nickel.query "oct 15 09" }
8
+
9
+ it "should have an empty message" do
10
+ @n.message.should be_empty
11
+ end
12
+
13
+ it "should have a start date" do
14
+ @n.occurrences.size.should == 1
15
+ @n.occurrences.first.start_date.should == "20091015"
16
+ end
17
+ end
18
+
19
+ describe "A daily occurrence" do
20
+ before(:all) do
21
+ @n = Nickel.query "wake up everyday at 11am"
22
+ @occurs = @n.occurrences.first
23
+ end
24
+
25
+ it "should have a message" do
26
+ @n.message.should == "wake up"
27
+ end
28
+
29
+ it "should be daily" do
30
+ @occurs.type.should == "daily"
31
+ end
32
+
33
+ it "should have a start time" do
34
+ @occurs.start_time.should == "11:00:00"
35
+ end
36
+ end
37
+
38
+
39
+ describe "A weekly occurrence" do
40
+ before(:all) do
41
+ @n = Nickel.query "guitar lessons every tuesday at 5pm"
42
+ @occurs = @n.occurrences.first
43
+ end
44
+
45
+ it "should have a message" do
46
+ @n.message.should == "guitar lessons"
47
+ end
48
+
49
+ it "should be weekly" do
50
+ @occurs.type.should == "weekly"
51
+ end
52
+
53
+
54
+ it "should occur on tuesdays" do
55
+ @occurs.day_of_week.should == "tue"
56
+ end
57
+
58
+ it "should occur once per week" do
59
+ @occurs.interval.should == 1
60
+ end
61
+
62
+ it "should start at 5pm" do
63
+ @occurs.start_time.should == "17:00:00"
64
+ end
65
+
66
+ it "should have a start date" do
67
+ @occurs.start_date.should_not be_nil
68
+ end
69
+
70
+ it "should not have an end date" do
71
+ @occurs.end_date.should be_nil
72
+ end
73
+ end
74
+
75
+
76
+ describe "A day monthly occurrence" do
77
+ before(:all) do
78
+ @n = Nickel.query "drink specials on the second thursday of every month"
79
+ @occurs = @n.occurrences.first
80
+ end
81
+
82
+ it "should have a message" do
83
+ @n.message.should == "drink specials"
84
+ end
85
+
86
+ it "should be day monthly" do
87
+ @occurs.type.should == "daymonthly"
88
+ end
89
+
90
+ it "should occur on second thursday of every month" do
91
+ @occurs.week_of_month.should == 2
92
+ @occurs.day_of_week.should == "thu"
93
+ end
94
+
95
+ it "should occur once per month" do
96
+ @occurs.interval.should == 1
97
+ end
98
+ end
99
+
100
+
101
+
102
+ describe "A date monthly occurrence" do
103
+ before(:all) do
104
+ @n = Nickel.query "pay credit card every month on the 22nd"
105
+ @occurs = @n.occurrences.first
106
+ end
107
+
108
+ it "should have a message" do
109
+ @n.message.should == "pay credit card"
110
+ end
111
+
112
+ it "should be date monthly" do
113
+ @occurs.type.should == "datemonthly"
114
+ end
115
+
116
+ it "should occur on the 22nd of every month" do
117
+ @occurs.date_of_month.should == 22
118
+ end
119
+
120
+ it "should occur once per month" do
121
+ @occurs.interval.should == 1
122
+ end
123
+ end
124
+
125
+
126
+ describe "Multiple occurrences" do
127
+ before(:all) do
128
+ @n = Nickel.query "band meeting every monday and wednesday at 2pm"
129
+ end
130
+
131
+ it "should have a message" do
132
+ @n.message.should == "band meeting"
133
+ end
134
+
135
+ it "should have two occurrences" do
136
+ @n.occurrences.size.should == 2
137
+ end
138
+
139
+ it "should occur on mondays and wednesdays" do
140
+ days = @n.occurrences.collect {|occ| occ.day_of_week}
141
+ days.include?("mon").should be_true
142
+ days.include?("wed").should be_true
143
+ days.size.should == 2
144
+ end
145
+
146
+ it "should occur at 2pm on both days" do
147
+ @n.occurrences[0].start_time.should == "14:00:00"
148
+ @n.occurrences[1].start_time.should == "14:00:00"
149
+ end
150
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nickel
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Lou Zell
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-31 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mapricot
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description: A client for naturalinputs.com. Extracts date, time, and message information from naturally worded text.
33
+ email: lzell11@gmail.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README.rdoc
40
+ files:
41
+ - README.rdoc
42
+ - History.txt
43
+ - License.txt
44
+ - nickel.gemspec
45
+ - test/nickel_spec.rb
46
+ - lib/nickel.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/lzell/nickel
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --main
54
+ - README.rdoc
55
+ - --title
56
+ - Nickel
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Natural language date and time parsing
80
+ test_files: []
81
+