nickel 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba3e838fa5d6806f85eb03ddf6732481d5d09947
4
- data.tar.gz: f1e5af3b3a1b16c2c9f5a67eedcdf479e37265c9
3
+ metadata.gz: 4749a62cf4e0593e14a0add9a87e83ab42c0e22a
4
+ data.tar.gz: 89f4306d7c4600d52ef806ef776dc2ebfaba4880
5
5
  SHA512:
6
- metadata.gz: 77c82d90eab894ed70b59e586bb8dab299e43fe2999d4d5e015f33dc133a8614bae437e4fbdf2f7aa75caccc721612123bb67fe778f07cb6dfa9fe82cbe783e7
7
- data.tar.gz: e95c789fd5d6c6ec167690a0e199b19411620faf0427bf4e302a10ed95a44ab00b8dafc1d74475c3ad3b074496ae1c647780f374bc511d3a0e2af1272d6849d7
6
+ metadata.gz: a679225d669ab812a0c260f8bef2012047aa24a709838b869228ab32eff4db78c1f65d81903b046a23746410542e2d563d03cb88077f24ec7d3c0af3c9d9c2b0
7
+ data.tar.gz: b9febf74771b71217f1ce05148bd17dd4939c3eb60b7d8f51856ddd9f30d221cd0fcf18d80bf7f9323a31a1f3d9f67d8dac36b2d9180dbf2e5fd8299c4dbc0f7
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  Nickel
2
2
  ======
3
3
 
4
- Nickel extracts date, time, and message information from naturally worded text.
5
-
6
4
  [![Gem Version](http://img.shields.io/gem/v/nickel.svg)](http://rubygems.org/gems/nickel)
7
5
  [![Build Status](http://img.shields.io/travis/iainbeeston/nickel/master.svg)](https://travis-ci.org/iainbeeston/nickel)
8
6
  [![Coverage Status](http://img.shields.io/coveralls/iainbeeston/nickel/master.svg)](https://coveralls.io/r/iainbeeston/nickel)
9
7
  [![Code Climate](http://img.shields.io/codeclimate/github/iainbeeston/nickel.svg)](https://codeclimate.com/github/iainbeeston/nickel)
10
8
 
9
+ Nickel extracts date, time, and message information from naturally worded text.
10
+
11
11
  Install
12
12
  -------
13
13
 
@@ -9,17 +9,7 @@ module Nickel
9
9
  end
10
10
 
11
11
  def inspect
12
- str = %(\#<Occurrence type: #{type})
13
- str << %(, start_date: "#{start_date}") if start_date
14
- str << %(, end_date: "#{end_date}") if end_date
15
- str << %(, start_time: "#{start_time}") if start_time
16
- str << %(, end_time: "#{end_time}") if end_time
17
- str << %(, interval: #{interval}) if interval
18
- str << %(, day_of_week: #{day_of_week}) if day_of_week
19
- str << %(, week_of_month: #{week_of_month}) if week_of_month
20
- str << %(, date_of_month: #{date_of_month}) if date_of_month
21
- str << ">"
22
- str
12
+ "#<Occurrence " + members.select{|m| self[m]}.map{|m| %(#{m}: #{self[m]})}.join(", ") + ">"
23
13
  end
24
14
 
25
15
  def finalize(cur_date)
@@ -1,3 +1,3 @@
1
1
  module Nickel
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/nickel/zdate.rb CHANGED
@@ -75,22 +75,12 @@ module Nickel
75
75
  txt.gsub!(/%d/, self.day_str)
76
76
  end
77
77
 
78
- def before(d2)
79
- d2.respond_to?(:year) && (year < d2.year) ||
80
- d2.respond_to?(:month) && (year == d2.year && (month < d2.month ||
81
- d2.respond_to?(:day) && (month == d2.month && day < d2.day)))
82
- end
83
-
84
- def after(d2)
85
- d2.respond_to?(:year) && (year > d2.year) ||
86
- d2.respond_to?(:month) && (year == d2.year && (month > d2.month ||
87
- d2.respond_to?(:day) && (month == d2.month && day > d2.day)))
88
- end
89
-
90
78
  def <=>(d2)
91
- if before(d2)
79
+ return nil unless [:year, :month, :day].all?{|m| d2.respond_to?(m)}
80
+
81
+ if before?(d2)
92
82
  -1
93
- elsif after(d2)
83
+ elsif after?(d2)
94
84
  1
95
85
  else
96
86
  0
@@ -555,6 +545,15 @@ module Nickel
555
545
  end
556
546
 
557
547
  private
548
+
549
+ def before?(d2)
550
+ (year < d2.year) || (year == d2.year && (month < d2.month || (month == d2.month && day < d2.day)))
551
+ end
552
+
553
+ def after?(d2)
554
+ (year > d2.year) || (year == d2.year && (month > d2.month || (month == d2.month && day > d2.day)))
555
+ end
556
+
558
557
  def validate
559
558
  raise "ZDate says: invalid date" if !valid
560
559
  end
data/lib/nickel/ztime.rb CHANGED
@@ -139,23 +139,12 @@ module Nickel
139
139
  is_am? ? "am" : "pm"
140
140
  end
141
141
 
142
-
143
- def before(t2)
144
- (t2.respond_to? :hour) && (hour < t2.hour) ||
145
- (t2.respond_to? :min) && (hour == t2.hour && (min < t2.min ||
146
- (t2.respond_to? :sec) && (min == t2.min && sec < t2.sec)))
147
- end
148
-
149
- def after(t2)
150
- (t2.respond_to? :hour) && (hour > t2.hour) ||
151
- (t2.respond_to? :min) && (hour == t2.hour && (min > t2.min ||
152
- (t2.respond_to? :sec) && (min == t2.min && sec > t2.sec)))
153
- end
154
-
155
142
  def <=>(t2)
156
- if before(t2)
143
+ return nil unless [:hour, :min, :sec].all?{|m| t2.respond_to?(m)}
144
+
145
+ if before?(t2)
157
146
  -1
158
- elsif after(t2)
147
+ elsif after?(t2)
159
148
  1
160
149
  else
161
150
  0
@@ -352,6 +341,14 @@ module Nickel
352
341
 
353
342
  private
354
343
 
344
+ def before?(t2)
345
+ (hour < t2.hour) || (hour == t2.hour && (min < t2.min || (min == t2.min && sec < t2.sec)))
346
+ end
347
+
348
+ def after?(t2)
349
+ (hour > t2.hour) || (hour == t2.hour && (min > t2.min || (min == t2.min && sec > t2.sec)))
350
+ end
351
+
355
352
  def adjust_for(am_pm)
356
353
  # how does validation work? Well, we already know that @time is valid, and once we modify we call time= which will
357
354
  # perform validation on the new time. That won't catch something like this though: ZTime.new("2215", :am)
@@ -35,6 +35,14 @@ module Nickel
35
35
  expect(occ).to eq Occurrence.new(type: :daily, start_date: ZDate.new("20140128"))
36
36
  end
37
37
  end
38
+
39
+ describe "#inspect" do
40
+ let(:occ) { Occurrence.new(type: :daily, start_date: ZDate.new("20140128"), end_date: ZDate.new("20140209"), interval: 2) }
41
+
42
+ it "shows only members that have been set" do
43
+ expect(occ.inspect).to eq '#<Occurrence type: daily, start_date: 20140128, end_date: 20140209, interval: 2>'
44
+ end
45
+ end
38
46
  end
39
47
  end
40
48
 
@@ -89,6 +89,10 @@ module Nickel
89
89
  it "is false when the other object is a Date for any other day" do
90
90
  expect(d1).to_not eq Date.new(2010, 9, 27)
91
91
  end
92
+
93
+ it "is false when the other object is a String" do
94
+ expect(d1).to_not eq '20090927'
95
+ end
92
96
  end
93
97
  end
94
98
  end
@@ -254,77 +254,69 @@ module Nickel
254
254
  it "is false when the other object is a Time for any other time" do
255
255
  expect(t1).to_not eq Time.parse("17:18:19")
256
256
  end
257
+
258
+ it "is false when the other object is a String" do
259
+ expect(t1).to_not eq "161718"
260
+ end
257
261
  end
258
262
 
259
263
  describe "#hour_str" do
260
264
  it "is the hour in the day as a string" do
261
- expect(ZTime.new("161718").hour_str).to eql("16")
265
+ expect(ZTime.new("161718").hour_str).to eq("16")
262
266
  end
263
267
  end
264
268
 
265
269
  describe "#min_str" do
266
270
  it "is the minutes past the hour as a string" do
267
- expect(ZTime.new("161718").min_str).to eql("17")
271
+ expect(ZTime.new("161718").min_str).to eq("17")
268
272
  end
269
273
  end
270
274
 
271
275
  describe "#sec_str" do
272
276
  it "is the seconds into the minute as a string" do
273
- expect(ZTime.new("161718").sec_str).to eql("18")
277
+ expect(ZTime.new("161718").sec_str).to eq("18")
274
278
  end
275
279
  end
276
280
 
277
281
  describe "#minute_str", :deprecated do
278
- let(:t1) { ZTime.new("161718") }
279
-
280
- it "delegates to #min_str" do
281
- expect(t1).to receive(:min_str)
282
- t1.minute_str
282
+ it "is the minutes past the hour as a string" do
283
+ expect(ZTime.new("161718").min_str).to eq("17")
283
284
  end
284
285
  end
285
286
 
286
287
  describe "#second_str", :deprecated do
287
- let(:t1) { ZTime.new("161718") }
288
-
289
- it "delegates to #sec_str" do
290
- expect(t1).to receive(:sec_str)
291
- t1.second_str
288
+ it "is the seconds into the minute as a string" do
289
+ expect(ZTime.new("161718").sec_str).to eq("18")
292
290
  end
293
291
  end
294
292
 
295
293
  describe "#hour" do
296
294
  it "is the hour in the day" do
297
- expect(ZTime.new("161718").hour).to eql(16)
295
+ expect(ZTime.new("161718").hour).to eq(16)
298
296
  end
299
297
  end
300
298
 
301
299
  describe "#min" do
302
300
  it "is the minutes past the hour" do
303
- expect(ZTime.new("161718").min).to eql(17)
301
+ expect(ZTime.new("161718").min).to eq(17)
304
302
  end
305
303
  end
306
304
 
307
305
  describe "#sec" do
308
306
  it "is the seconds into the minute" do
309
- expect(ZTime.new("161718").sec).to eql(18)
307
+ expect(ZTime.new("161718").sec).to eq(18)
310
308
  end
311
309
  end
312
310
 
313
311
  describe "#minute", :deprecated do
314
- let(:t1) { ZTime.new("161718") }
315
-
316
- it "delegates to #min" do
317
- expect(t1).to receive(:min)
318
- t1.minute
312
+ it "is the minutes past the hour" do
313
+ expect(ZTime.new("161718").min).to eq(17)
319
314
  end
320
315
  end
321
316
 
322
317
  describe "#second", :deprecated do
323
- let(:t1) { ZTime.new("161718") }
324
-
325
- it "delegates to #sec" do
326
- expect(t1).to receive(:sec)
327
- t1.second
318
+ it "is the seconds into the minute" do
319
+ expect(ZTime.new("161718").sec).to eq(18)
328
320
  end
329
321
  end
330
322
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nickel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Zell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-15 00:00:00.000000000 Z
12
+ date: 2014-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler