usaidwat 0.1.6 → 0.1.7

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: cb020c71be1b1132ce622e958ce732fd29ef086b
4
- data.tar.gz: 629f6f970557e968bab7d850d4ee1c101f1c66a7
3
+ metadata.gz: 2042e843c42b44f059297bb23e7350e9b0575978
4
+ data.tar.gz: 2a716a7208ab8af75b394701bd3b691f405b6a97
5
5
  SHA512:
6
- metadata.gz: de40783e531b166a72f99c401a05007383b2f237dbe1717679fbd4ac6ed2750865e66bec4c5520cd25963faf4c4e6bfe0bf703f11fc7860ef712125573c89309
7
- data.tar.gz: e825e1c9517ce21aea8ec086c1e23aec34ee2062cdb46ac0bd61f2aeb24c03677a6429d7b4b465eaf13496b5ab931c7273993b9576f3d89a3c5de355af8ed4d7
6
+ metadata.gz: 4ed1d0358a6a8156dd27ac8f5e4bda3c2836874d126c8c40c850e07aa466c13d43fa1a0941b80ceddced3a52c56f5ba012f8a60f536ee21c7df91472ef162a51
7
+ data.tar.gz: 6a49f252762dd2664fb15f33b9966212ce0155e74d92c4771f17e91e021d34c95577313544ec88ebcbed5cd45b74cc2919af3504c4b0658479203e2dc9da31ff
data/Gemfile CHANGED
@@ -2,7 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in usaidwat.gemspec
4
4
  gemspec
5
-
6
- group :optional do
7
- gem 'nyan-cat-formatter'
8
- end
@@ -6,13 +6,14 @@ Feature: Browse comments
6
6
 
7
7
  Scenario: List all comments
8
8
  Given the Reddit service returns comments for the user "mipadi"
9
+ And time is frozen at Jun 24, 2015 11:05 AM
9
10
  When I run `usaidwat mipadi`
10
11
  Then it should pass with:
11
12
  """
12
13
  wikipedia
13
14
  http://www.reddit.com/r/wikipedia/comments/142t4w/z/c79peed
14
15
  Heisenbug: a software bug that seems to disappear or alter its behavior when one
15
- 01 Dec 2012, 12:14 PM
16
+ over 3 years ago
16
17
 
17
18
  Yep. My first experience with a Heisenbug occurred in a C++ program, and disappeared when I tried to print a variable with printf (only to reappear when that call was removed).
18
19
 
@@ -20,7 +21,7 @@ Feature: Browse comments
20
21
  nyc
21
22
  http://www.reddit.com/r/nyc/comments/141zqc/z/c79dxg6
22
23
  NYC taxi roof lights get overhaul - A light simply will mean the cab is availab
23
- 30 Nov 2012, 04:44 PM
24
+ over 3 years ago
24
25
 
25
26
  It has a fare when the lights are *off.*
26
27
 
@@ -28,17 +29,17 @@ Feature: Browse comments
28
29
  worldnews
29
30
  http://www.reddit.com/r/worldnews/comments/140mra/z/c797jq4
30
31
  Palestinians win upgraded UN status by wide margin
31
- 30 Nov 2012, 10:09 AM
32
+ over 3 years ago
32
33
 
33
34
  The Judgment of Solomon Accords.
34
35
  """
35
36
 
36
37
  Scenario: List all comments for a user that does not exist
37
- Given the Reddit service does not have a user "palorchild"
38
- When I run `usaidwat palorchild`
38
+ Given the Reddit service does not have a user "testuser"
39
+ When I run `usaidwat testuser`
39
40
  Then it should fail with:
40
41
  """
41
- No such user: palorchild
42
+ No such user: testuser
42
43
  """
43
44
 
44
45
  Scenario: List all comments when user has no comments
@@ -69,6 +70,26 @@ Feature: Browse comments
69
70
  worldnews 2
70
71
  """
71
72
 
73
+ Scenario: Sort comments
74
+ Given the Reddit service returns comments for the user "mipadi"
75
+ When I run `usaidwat -T mipadi`
76
+ Then it should pass with:
77
+ """
78
+ AskReddit 61
79
+ programming 20
80
+ apple 6
81
+ battlefield3 2
82
+ books 2
83
+ worldnews 2
84
+ django 1
85
+ Games 1
86
+ nyc 1
87
+ personalfinance 1
88
+ photography 1
89
+ redditcasual 1
90
+ wikipedia 1
91
+ """
92
+
72
93
  Scenario: Tally comments when user has no comments
73
94
  Given the Reddit service returns comments for the user "blank"
74
95
  When I run `usaidwat -t blank`
@@ -77,15 +98,24 @@ Feature: Browse comments
77
98
  blank has no comments.
78
99
  """
79
100
 
101
+ Scenario: Sort comments when user has no comments
102
+ Given the Reddit service returns comments for the user "blank"
103
+ When I run `usaidwat -T blank`
104
+ Then it should pass with:
105
+ """
106
+ blank has no comments.
107
+ """
108
+
80
109
  Scenario: List comments for a particular subreddit
81
110
  Given the Reddit service returns comments for the user "mipadi"
111
+ And time is frozen at Jun 24, 2015 11:05 AM
82
112
  When I run `usaidwat mipadi AskReddit`
83
113
  Then it should pass with:
84
114
  """
85
115
  AskReddit
86
116
  http://www.reddit.com/r/AskReddit/comments/141kt9/z/c795rwz
87
117
  Do colleges actually teach students how to think critically? Or even to think/qu
88
- 30 Nov 2012, 08:27 AM
118
+ over 3 years ago
89
119
 
90
120
  I think it depends on where you go and what you study, but yes, I think they do teach you to think critically, especially in humanities courses and seminars. Maybe it's just because I went to a small, private liberal arts college rather than a huge school, but critical thinking was definitely a part of my education.
91
121
 
@@ -93,7 +123,7 @@ Feature: Browse comments
93
123
  AskReddit
94
124
  http://www.reddit.com/r/AskReddit/comments/140t5c/z/c795nw3
95
125
  I'm from Tennessee and most of our jokes are geared toward Mississippi and Alaba
96
- 30 Nov 2012, 08:20 AM
126
+ over 3 years ago
97
127
 
98
128
  You're from New Jersey? Which exit?
99
129
 
@@ -101,20 +131,21 @@ Feature: Browse comments
101
131
  AskReddit
102
132
  http://www.reddit.com/r/AskReddit/comments/140h3z/z/c795muo
103
133
  Today I was going 80mph in a 55 when an unmarked police car pulled up next to me
104
- 30 Nov 2012, 08:19 AM
134
+ over 3 years ago
105
135
 
106
136
  You didn't slow down for very long though, did you?
107
137
  """
108
138
 
109
139
  Scenario: List comments for a particular subreddit specified with the wrong case
110
140
  Given the Reddit service returns comments for the user "mipadi"
141
+ And time is frozen at Jun 24, 2015 11:05 AM
111
142
  When I run `usaidwat mipadi askreddit`
112
143
  Then it should pass with:
113
144
  """
114
145
  AskReddit
115
146
  http://www.reddit.com/r/AskReddit/comments/141kt9/z/c795rwz
116
147
  Do colleges actually teach students how to think critically? Or even to think/qu
117
- 30 Nov 2012, 08:27 AM
148
+ over 3 years ago
118
149
 
119
150
  I think it depends on where you go and what you study, but yes, I think they do teach you to think critically, especially in humanities courses and seminars. Maybe it's just because I went to a small, private liberal arts college rather than a huge school, but critical thinking was definitely a part of my education.
120
151
 
@@ -122,7 +153,7 @@ Feature: Browse comments
122
153
  AskReddit
123
154
  http://www.reddit.com/r/AskReddit/comments/140t5c/z/c795nw3
124
155
  I'm from Tennessee and most of our jokes are geared toward Mississippi and Alaba
125
- 30 Nov 2012, 08:20 AM
156
+ over 3 years ago
126
157
 
127
158
  You're from New Jersey? Which exit?
128
159
 
@@ -130,7 +161,7 @@ Feature: Browse comments
130
161
  AskReddit
131
162
  http://www.reddit.com/r/AskReddit/comments/140h3z/z/c795muo
132
163
  Today I was going 80mph in a 55 when an unmarked police car pulled up next to me
133
- 30 Nov 2012, 08:19 AM
164
+ over 3 years ago
134
165
 
135
166
  You didn't slow down for very long though, did you?
136
167
  """
@@ -148,7 +179,15 @@ Feature: Browse comments
148
179
  When I run `usaidwat -t mipadi AskReddit`
149
180
  Then it should fail with:
150
181
  """
151
- Usage: usaidwat [-t] <user> [<subreddit>]
182
+ Usage: usaidwat [-t | -T] <user> [<subreddit>]
183
+ """
184
+
185
+ Scenario: Sort comments with subreddit
186
+ Given the Reddit service returns comments for the user "mipadi"
187
+ When I run `usaidwat -T mipadi AskReddit`
188
+ Then it should fail with:
189
+ """
190
+ Usage: usaidwat [-t | -T] <user> [<subreddit>]
152
191
  """
153
192
 
154
193
  Scenario: Pass no arguments
@@ -156,7 +195,7 @@ Feature: Browse comments
156
195
  When I run `usaidwat`
157
196
  Then it should fail with:
158
197
  """
159
- Usage: usaidwat [-t] <user> [<subreddit>]
198
+ Usage: usaidwat [-t | -T] <user> [<subreddit>]
160
199
  """
161
200
 
162
201
  Scenario: Pass no arguments when tallying
@@ -164,5 +203,13 @@ Feature: Browse comments
164
203
  When I run `usaidwat -t`
165
204
  Then it should fail with:
166
205
  """
167
- Usage: usaidwat [-t] <user> [<subreddit>]
206
+ Usage: usaidwat [-t | -T] <user> [<subreddit>]
207
+ """
208
+
209
+ Scenario: Pass no arguments when sorting
210
+ Given the Reddit service returns comments for the user "mipadi"
211
+ When I run `usaidwat -T`
212
+ Then it should fail with:
213
+ """
214
+ Usage: usaidwat [-t | -T] <user> [<subreddit>]
168
215
  """
@@ -8,7 +8,7 @@ Feature: Get help
8
8
  When I run `usaidwat --help`
9
9
  Then it should pass with:
10
10
  """
11
- Usage: usaidwat [-t] <user> [<subreddit>]
11
+ Usage: usaidwat [-t | -T] <user> [<subreddit>]
12
12
  """
13
13
 
14
14
  Scenario: Get version
@@ -0,0 +1,3 @@
1
+ Given /^time is frozen at (.+)$/ do |time|
2
+ Timecop.freeze(Time.parse(time))
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'timecop'
2
+
3
+ After do
4
+ Timecop.return
5
+ end
@@ -0,0 +1,31 @@
1
+ module USaidWat
2
+ module Algorithms
3
+ class Algorithm
4
+ attr_reader :buckets
5
+
6
+ def initialize(buckets)
7
+ @buckets = buckets
8
+ end
9
+
10
+ def sort(a, b)
11
+ a <=> b
12
+ end
13
+ end
14
+
15
+ class LexicographicalAlgorithm < Algorithm
16
+ def sort(a, b)
17
+ a.downcase <=> b.downcase
18
+ end
19
+ end
20
+
21
+ class CountAlgorithm < Algorithm
22
+ def sort(a, b)
23
+ if buckets[a] == buckets[b]
24
+ a.downcase <=> b.downcase
25
+ else
26
+ buckets[b] <=> buckets[a]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -17,6 +17,7 @@ module USaidWat
17
17
  opts, args = handle_arguments(argv)
18
18
  username = args.first
19
19
  @redditor = @client.new(username)
20
+ @algo = opts.algorithm
20
21
  begin
21
22
  return tally_comments if opts.tally
22
23
  return list_comments_for_subreddit(args[1]) if args.length == 2
@@ -27,7 +28,7 @@ module USaidWat
27
28
  end
28
29
 
29
30
  def usage(code=0)
30
- puts "Usage: usaidwat [-t] <user> [<subreddit>]"
31
+ puts "Usage: usaidwat [-t | -T] <user> [<subreddit>]"
31
32
  exit code
32
33
  end
33
34
 
@@ -68,7 +69,8 @@ module USaidWat
68
69
  longest_subreddit = subreddit.length if subreddit.length > longest_subreddit
69
70
  buckets[subreddit] += 1
70
71
  end
71
- subreddits = buckets.keys.sort { |a,b| a.downcase <=> b.downcase }
72
+ algo = @algo.new(buckets)
73
+ subreddits = buckets.keys.sort { |a,b| algo.sort(a, b) }
72
74
  subreddits.each do |subreddit|
73
75
  tally = buckets[subreddit]
74
76
  printf "%-*s %3d\n", longest_subreddit, subreddit, tally
@@ -80,11 +82,13 @@ module USaidWat
80
82
  def handle_arguments(argv)
81
83
  opts = OpenStruct.new
82
84
  opts.tally = false
85
+ opts.algorithm = USaidWat::Algorithms::LexicographicalAlgorithm
83
86
  usage(1) if argv.length == 0
84
87
  usage if argv.first == "--help"
85
88
  version if argv.first == "--version"
86
- if argv.first == "-t"
89
+ if %W{-t -T}.include?(argv.first)
87
90
  opts.tally = true
91
+ opts.algorithm = USaidWat::Algorithms::CountAlgorithm if argv.first == "-T"
88
92
  argv.shift
89
93
  usage(1) unless argv.length == 1
90
94
  end
@@ -6,4 +6,12 @@ class String
6
6
  def convert_entities
7
7
  self.gsub(/&gt;/, '>').gsub(/&lt;/, '<')
8
8
  end
9
+
10
+ def pluralize(n, suffix = 's', singular_suffix = '')
11
+ if n == 1
12
+ self + singular_suffix
13
+ else
14
+ self + suffix
15
+ end
16
+ end
9
17
  end
@@ -0,0 +1,86 @@
1
+ require 'usaidwat/ext/string'
2
+
3
+ class Time
4
+ def ago
5
+ case minutes_ago
6
+ when 0..1
7
+ case seconds_ago
8
+ when 0..5 then "less than 5 seconds ago"
9
+ when 6..10 then "less than 10 seconds ago"
10
+ when 11..20 then "less than 20 seconds ago"
11
+ when 21..40 then "half a minute ago"
12
+ when 41..59 then "less than a minute ago"
13
+ else "a minute ago"
14
+ end
15
+ when 2..45 then "#{minutes_ago.round} minutes ago"
16
+ when 46..90 then "about an hour ago"
17
+ when 90..1440 then "about #{hours_ago.round} hours ago"
18
+ when 1441..2880 then "a day ago"
19
+ when 2881..10080 then "about #{days_ago.round} days ago"
20
+ when 10081..43220 then "about #{weeks_ago.round} #{"week".pluralize(weeks_ago.round)} ago"
21
+ when 43221..525960 then "about #{months_ago.round} #{"month".pluralize(months_ago.round)} ago"
22
+ when 525960..1051920 then "about a year ago"
23
+ else "over #{years_ago.round} years ago"
24
+ end
25
+ end
26
+
27
+ def seconds_ago
28
+ Time.now.to_i - to_i
29
+ end
30
+
31
+ def minutes_ago
32
+ seconds_ago / 60.0
33
+ end
34
+
35
+ def hours_ago
36
+ minutes_ago / 60.0
37
+ end
38
+
39
+ def days_ago
40
+ hours_ago / 24.0
41
+ end
42
+
43
+ def weeks_ago
44
+ days_ago / 7.0
45
+ end
46
+
47
+ def months_ago
48
+ days_ago / 30.0
49
+ end
50
+
51
+ def years_ago
52
+ days_ago / 365.0
53
+ end
54
+ end
55
+
56
+ class Integer
57
+ def seconds
58
+ self
59
+ end
60
+ alias_method :second, :seconds
61
+
62
+ def minutes
63
+ self * 60
64
+ end
65
+ alias_method :minute, :minutes
66
+
67
+ def hours
68
+ minutes * 60
69
+ end
70
+ alias_method :hour, :hours
71
+
72
+ def days
73
+ hours * 24
74
+ end
75
+ alias_method :day, :days
76
+
77
+ def weeks
78
+ days * 7
79
+ end
80
+ alias_method :week, :weeks
81
+
82
+ def years
83
+ days * 365
84
+ end
85
+ alias_method :year, :years
86
+ end
@@ -3,6 +3,7 @@ require 'highline'
3
3
  require 'stringio'
4
4
  require 'rainbow/ext/string'
5
5
  require 'usaidwat/ext/string'
6
+ require 'usaidwat/ext/time'
6
7
 
7
8
  Rainbow.enabled = true unless ENV['USAIDWAT_ENV'] == 'cucumber'
8
9
 
@@ -35,8 +36,7 @@ module USaidWat
35
36
  end
36
37
 
37
38
  def comment_date(comment)
38
- fmt = ENV['USAIDWAT_TIME_FORMAT'] || '%d %b %Y, %I:%M %p'
39
- DateTime.strptime(comment.created_utc.to_s, "%s").to_time.localtime.strftime(fmt)
39
+ DateTime.strptime(comment.created_utc.to_s, "%s").to_time.localtime.ago
40
40
  end
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module USaidWat
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/usaidwat.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "usaidwat/algo"
1
2
  require "usaidwat/application"
2
3
  require "usaidwat/formatter"
3
4
  require "usaidwat/client"
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module USaidWat
4
+ module Algorithms
5
+ describe LexicographicalAlgorithm do
6
+ let (:algo) { LexicographicalAlgorithm.new(nil) }
7
+
8
+ it "should return -1 if the first object is before the second" do
9
+ expect(algo.sort("a", "b")).to eq(-1)
10
+ end
11
+
12
+ it "should return 1 if the first object is after the second" do
13
+ expect(algo.sort("b", "a")).to eq(1)
14
+ end
15
+
16
+ it "should return 0 if the objects are equal" do
17
+ expect(algo.sort("a", "a")).to eq(0)
18
+ end
19
+
20
+ it "should ignore case when comparing objects that are ordered" do
21
+ expect(algo.sort("a", "B")).to eq(-1)
22
+ end
23
+
24
+ it "should ignore case when comparing objects that are ordered in reverse" do
25
+ expect(algo.sort("B", "a")).to eq(1)
26
+ end
27
+
28
+ it "should ignore case when comparing equal objects" do
29
+ expect(algo.sort("A", "a")).to eq(0)
30
+ end
31
+ end
32
+
33
+ describe CountAlgorithm do
34
+ let (:algo) { CountAlgorithm.new({"a" => 10, "b" => 20, "c" => 5, "d" => 10}) }
35
+
36
+ it "should return -1 if the first object has a higher count than the second" do
37
+ expect(algo.sort("b", "a")).to eq(-1)
38
+ end
39
+
40
+ it "should return 1 if the first object has a lower count than the second" do
41
+ expect(algo.sort("a", "b")).to eq(1)
42
+ end
43
+
44
+ it "should return -1 if the objects have the same count but the first occurs first alphabetically" do
45
+ expect(algo.sort("a", "d")).to eq(-1)
46
+ end
47
+
48
+ it "should return 1 if the objects have the same count but the second occurs first alphabetically" do
49
+ expect(algo.sort("d", "a")).to eq(1)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -38,13 +38,13 @@ module USaidWat
38
38
  WebMock.disable_net_connect!
39
39
  WebMock.reset!
40
40
  root = File.expand_path("../../../features/fixtures", __FILE__)
41
- stub_request(:get, "http://www.reddit.com/user/palorchild/comments.json?after=&limit=100").
42
- to_return(:status => 404, :body => IO.read(File.join(root, "palorchild.json")))
41
+ stub_request(:get, "http://www.reddit.com/user/testuser/comments.json?after=&limit=100").
42
+ to_return(:status => 404, :body => IO.read(File.join(root, "testuser.json")))
43
43
  end
44
44
 
45
45
  describe "#comments" do
46
46
  it "raises an exception if the user does not exist" do
47
- expect { Redditor.new("palorchild").comments }.to raise_error(NoSuchUserError, /palorchild/)
47
+ expect { Redditor.new("testuser").comments }.to raise_error(NoSuchUserError, /testuser/)
48
48
  end
49
49
  end
50
50
  end
@@ -1,9 +1,18 @@
1
1
  require 'spec_helper'
2
+ require 'timecop'
2
3
 
3
4
  module USaidWat
4
5
  module CLI
5
6
  describe CommentFormatter do
6
7
  let(:formatter) { CommentFormatter.new }
8
+
9
+ before do
10
+ Timecop.freeze(Time.new(2015, 6, 16, 17, 8))
11
+ end
12
+
13
+ after do
14
+ Timecop.return
15
+ end
7
16
 
8
17
  describe "#format" do
9
18
  it "should return a string containing the formatted comment" do
@@ -18,7 +27,7 @@ module USaidWat
18
27
  programming
19
28
  http://www.reddit.com/r/programming/comments/13f783/z/c73qhxi
20
29
  Why Brit Ruby 2013 was cancelled and why this is not ok - Gist
21
- 03 Jun 2015, 05:38 PM
30
+ about 2 weeks ago
22
31
 
23
32
  Welcome to the wonderful world of Python drama!
24
33
  EXPECTED
@@ -25,6 +25,48 @@ module USaidWat
25
25
  expect(actual).to eq(expected)
26
26
  end
27
27
  end
28
+
29
+ describe "#truncate" do
30
+ it "truncates strings longer than the given width to the width" do
31
+ n = 80
32
+ s = "-" * n * 2
33
+ expect(s.truncate(n).length).to eq(n)
34
+ end
35
+
36
+ it "does not change strings shorter than the given width" do
37
+ n = 80
38
+ s = "string"
39
+ expect(s.truncate(n).length).to eq(s.length)
40
+ expect(s.truncate(n).length).to be < n
41
+ end
42
+ end
43
+
44
+ describe "#pluralize" do
45
+ it "should not append an 's' to a singular noun" do
46
+ s = "dog"
47
+ expect(s.pluralize(1)).to eq(s)
48
+ end
49
+
50
+ it "should append an 's' to a plural noun" do
51
+ s = "dog"
52
+ expect(s.pluralize(2)).to eq("dogs")
53
+ end
54
+
55
+ it "should append an 's' to a noun with count 0" do
56
+ s = "dog"
57
+ expect(s.pluralize(0)).to eq("dogs")
58
+ end
59
+
60
+ it "should append 'ies' to a plural noun" do
61
+ s = "popp"
62
+ expect(s.pluralize(2, "ies", "y")).to eq("poppies")
63
+ end
64
+
65
+ it "should not append 'ies' to a singular noun" do
66
+ s = "popp"
67
+ expect(s.pluralize(1, "ies", "y")).to eq("poppy")
68
+ end
69
+ end
28
70
  end
29
71
  end
30
72
  end
@@ -0,0 +1,204 @@
1
+ require 'spec_helper'
2
+ require 'timecop'
3
+
4
+ module USaidWat
5
+ module Ext
6
+ describe Integer do
7
+ describe "#seconds" do
8
+ it "should convert itself into seconds" do
9
+ expect(10.seconds).to eq(10)
10
+ end
11
+
12
+ it "should accept a singular form of seconds" do
13
+ expect(1.second).to eq(1)
14
+ end
15
+
16
+ it "should convert itself into minutes" do
17
+ expect(10.minutes).to eq(600)
18
+ end
19
+
20
+ it "should accept a singular form of minutes" do
21
+ expect(1.minute).to eq(60)
22
+ end
23
+
24
+ it "should convert itself into hours" do
25
+ expect(10.hours).to eq(36_000)
26
+ end
27
+
28
+ it "should accept a singular form of hours" do
29
+ expect(1.hour).to eq(3600)
30
+ end
31
+
32
+ it "should convert itself into days" do
33
+ expect(10.days).to eq(864_000)
34
+ end
35
+
36
+ it "should accept a singular form of days" do
37
+ expect(1.day).to eq(86_400)
38
+ end
39
+
40
+ it "should convert itself into weeks" do
41
+ expect(10.weeks).to eq(6_048_000)
42
+ end
43
+
44
+ it "should accept a singular form of weeks" do
45
+ expect(1.week).to eq(604_800)
46
+ end
47
+
48
+ it "should convert itself into years" do
49
+ expect(10.years).to eq(315_360_000)
50
+ end
51
+
52
+ it "should accept a singular form of years" do
53
+ expect(1.year).to eq(31_536_000)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe Time do
59
+ before do
60
+ Timecop.freeze(2015, 6, 23, 17, 22, 0)
61
+ end
62
+
63
+ after do
64
+ Timecop.return
65
+ end
66
+
67
+ describe "#seconds_ago" do
68
+ it "returns the elapsed seconds between now and then" do
69
+ then_ = Time.new(2015, 6, 23, 17, 21, 25)
70
+ expect(then_.seconds_ago).to eq(35)
71
+ end
72
+ end
73
+
74
+ describe "#minutes_ago" do
75
+ it "returns the elapsed minutes between now and then" do
76
+ then_ = Time.new(2015, 6, 23, 17, 20, 30)
77
+ expect(then_.minutes_ago).to be_within(0.01).of(1.5)
78
+ end
79
+ end
80
+
81
+ describe "#hours_ago" do
82
+ it "returns the elapsed hours between now and then" do
83
+ then_ = Time.new(2015, 6, 23, 13, 12)
84
+ expect(then_.hours_ago).to be_within(0.01).of(4.16)
85
+ end
86
+ end
87
+
88
+ describe "#days_ago" do
89
+ it "returns the elapsed days between now and then" do
90
+ then_ = Time.new(2015, 6, 18, 8, 14)
91
+ expect(then_.days_ago).to be_within(0.01).of(5.38)
92
+ end
93
+ end
94
+
95
+ describe "#weeks_ago" do
96
+ it "returns the elapsed weeks between now and then" do
97
+ then_ = Time.new(2015, 5, 26, 12, 14)
98
+ expect(then_.weeks_ago).to be_within(0.01).of(4.03)
99
+ end
100
+ end
101
+
102
+ describe "#months_ago" do
103
+ it "returns the elapsed months between now and then" do
104
+ then_ = Time.new(2013, 12, 25, 7, 49)
105
+ expect(then_.months_ago).to be_within(0.01).of(18.17)
106
+ end
107
+ end
108
+
109
+ describe "#years_ago" do
110
+ it "returns the elapsed years between now and then" do
111
+ then_ = Time.new(1988, 4, 1, 21, 32)
112
+ expect(then_.years_ago).to be_within(0.01).of(27.24)
113
+ end
114
+ end
115
+
116
+ describe "#ago" do
117
+ it "should respond when then was a few seconds ago" do
118
+ then_ = Time.now - 5
119
+ expect(then_.ago).to eq("less than 5 seconds ago")
120
+ end
121
+
122
+ it "should respond when then was less than 10 seconds ago" do
123
+ then_ = Time.now - 10
124
+ expect(then_.ago).to eq("less than 10 seconds ago")
125
+ end
126
+
127
+ it "should respond when then was less than 20 seconds ago" do
128
+ then_ = Time.now - 20
129
+ expect(then_.ago).to eq("less than 20 seconds ago")
130
+ end
131
+
132
+ it "should respond when then was less than a half minute ago" do
133
+ then_ = Time.now - 40
134
+ expect(then_.ago).to eq("half a minute ago")
135
+ end
136
+
137
+ it "should respond when then was less than a minute ago" do
138
+ then_ = Time.now - 59
139
+ expect(then_.ago).to eq("less than a minute ago")
140
+ end
141
+
142
+ it "should respond when then was a minute ago" do
143
+ then_ = Time.now - 1.minute
144
+ expect(then_.ago).to eq("a minute ago")
145
+ end
146
+
147
+ it "should respond when then was several minutes ago" do
148
+ then_ = Time.now - 45.minutes
149
+ expect(then_.ago).to eq("45 minutes ago")
150
+ end
151
+
152
+ it "should respond when then was an hour ago" do
153
+ then_ = Time.now - 90.minutes
154
+ expect(then_.ago).to eq("about an hour ago")
155
+ end
156
+
157
+ it "should respond when then was several hours ago" do
158
+ then_ = Time.now - 1440.minutes
159
+ expect(then_.ago).to eq("about 24 hours ago")
160
+ end
161
+
162
+ it "should respond when then was a day ago" do
163
+ then_ = Time.now - 2880.minutes
164
+ expect(then_.ago).to eq("a day ago")
165
+ end
166
+
167
+ it "should respond when then was several days ago" do
168
+ then_ = Time.now - 10080.minutes
169
+ expect(then_.ago).to eq("about 7 days ago")
170
+ end
171
+
172
+ it "should respond when then was a week ago" do
173
+ then_ = Time.now - 1.week - 1.minute
174
+ expect(then_.ago).to eq("about 1 week ago")
175
+ end
176
+
177
+ it "should respond when then was several weeks ago" do
178
+ then_ = Time.now - 43220.minutes
179
+ expect(then_.ago).to eq("about 4 weeks ago")
180
+ end
181
+
182
+ it "should respond when then was a month ago" do
183
+ then_ = Time.now - 43221.minutes
184
+ expect(then_.ago).to eq("about 1 month ago")
185
+ end
186
+
187
+ it "should respond when then was several months ago" do
188
+ then_ = Time.now - 180.days
189
+ expect(then_.ago).to eq("about 6 months ago")
190
+ end
191
+
192
+ it "should respond when then was a year ago" do
193
+ then_ = Time.now - 1051920.minutes
194
+ expect(then_.ago).to eq("about a year ago")
195
+ end
196
+
197
+ it "should respond when then was several years ago" do
198
+ then_ = Time.now - 1051920.minutes - 1
199
+ expect(then_.ago).to eq("over 2 years ago")
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
data/usaidwat.gemspec CHANGED
@@ -22,8 +22,9 @@ Gem::Specification.new do |gem|
22
22
  gem.add_runtime_dependency('rainbow', '~> 2.0')
23
23
  gem.add_runtime_dependency('highline', '~> 1.7', '>= 1.7.2')
24
24
 
25
- gem.add_development_dependency('rspec', '~> 3.2')
26
- gem.add_development_dependency('cucumber', '~> 2.0')
27
25
  gem.add_development_dependency('aruba', '~> 0.6.2')
26
+ gem.add_development_dependency('cucumber', '~> 2.0')
27
+ gem.add_development_dependency('rspec', '~> 3.2')
28
+ gem.add_development_dependency('timecop', '~> 0.7.4')
28
29
  gem.add_development_dependency('webmock', '~> 1.21')
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usaidwat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dippery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: snooby
@@ -59,19 +59,19 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.7.2
61
61
  - !ruby/object:Gem::Dependency
62
- name: rspec
62
+ name: aruba
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.2'
67
+ version: 0.6.2
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '3.2'
74
+ version: 0.6.2
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: cucumber
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -87,19 +87,33 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2.0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: aruba
90
+ name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: 0.6.2
95
+ version: '3.2'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 0.6.2
102
+ version: '3.2'
103
+ - !ruby/object:Gem::Dependency
104
+ name: timecop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.7.4
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.7.4
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: webmock
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -131,22 +145,28 @@ files:
131
145
  - features/browse.feature
132
146
  - features/fixtures/blank.json
133
147
  - features/fixtures/mipadi.json
134
- - features/fixtures/palorchild.json
148
+ - features/fixtures/testuser.json
135
149
  - features/help.feature
136
150
  - features/step_definitions/reddit_steps.rb
151
+ - features/step_definitions/time_steps.rb
137
152
  - features/support/aruba.rb
153
+ - features/support/time.rb
138
154
  - lib/usaidwat.rb
155
+ - lib/usaidwat/algo.rb
139
156
  - lib/usaidwat/application.rb
140
157
  - lib/usaidwat/client.rb
141
158
  - lib/usaidwat/ext/string.rb
159
+ - lib/usaidwat/ext/time.rb
142
160
  - lib/usaidwat/formatter.rb
143
161
  - lib/usaidwat/service.rb
144
162
  - lib/usaidwat/version.rb
145
163
  - spec/spec_helper.rb
164
+ - spec/usaidwat/algo_spec.rb
146
165
  - spec/usaidwat/client_spec.rb
147
166
  - spec/usaidwat/formatter_spec.rb
148
167
  - spec/usaidwat/service_spec.rb
149
168
  - spec/usaidwat/string_spec.rb
169
+ - spec/usaidwat/time_spec.rb
150
170
  - usaidwat.gemspec
151
171
  homepage: https://github.com/mdippery/usaidwat
152
172
  licenses:
@@ -176,12 +196,16 @@ test_files:
176
196
  - features/browse.feature
177
197
  - features/fixtures/blank.json
178
198
  - features/fixtures/mipadi.json
179
- - features/fixtures/palorchild.json
199
+ - features/fixtures/testuser.json
180
200
  - features/help.feature
181
201
  - features/step_definitions/reddit_steps.rb
202
+ - features/step_definitions/time_steps.rb
182
203
  - features/support/aruba.rb
204
+ - features/support/time.rb
183
205
  - spec/spec_helper.rb
206
+ - spec/usaidwat/algo_spec.rb
184
207
  - spec/usaidwat/client_spec.rb
185
208
  - spec/usaidwat/formatter_spec.rb
186
209
  - spec/usaidwat/service_spec.rb
187
210
  - spec/usaidwat/string_spec.rb
211
+ - spec/usaidwat/time_spec.rb