time_to_read 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: 83657e2ca796b3347edddaa6b0d1b61bc27041a6
4
- data.tar.gz: 6a0b8cda9be1437afcb66bdf396698a2b5923536
3
+ metadata.gz: 24b42f86eeff5b2e17481a8942b60c6614851f78
4
+ data.tar.gz: 79e95a32883bcf93799fbcc35839ef36ca79338a
5
5
  SHA512:
6
- metadata.gz: 887391409c223276f1763e278a138f00032b8ade8c3fe76ec9666fd5a9ce35329f170b537193a377820973e06eb562a0ce2b7d55c4b68542f3a71cdb4862cb4c
7
- data.tar.gz: ffc0c5143754d472fa01799f7013996abc7d8171a3e976526ff96662c20524c752b59657dc01016d70596f8ae04e0cca530c0f7e8f126fe0cbd2f12198a1b7ce
6
+ metadata.gz: ab93072243f14cbd48cb1b9024605249a34f54c926dce8a87ff57a18e285245f1f8e7a40301f98b8f097985ecf45aab74027f812b891a5d2291f4f388f07cc51
7
+ data.tar.gz: 38b9bb09e4d0f12349f2e00199356505b8b5b3a3e43ec1c099d5386d61c94dcbbcc3faf501dd11e446881b988495795e95aba5e86dc46c2c0c0f1a05b87de354
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ReadTimeEstimator
1
+ # TimeToRead
2
2
 
3
3
  Estimates the time to read a string of text. The gem assumes a reading speed of 250 words per minute.
4
4
 
@@ -6,7 +6,7 @@ Estimates the time to read a string of text. The gem assumes a reading speed of
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'read_time_estimator'
9
+ gem 'time_to_read'
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,21 +14,23 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install read_time_estimator
17
+ $ gem install time_to_read
18
18
 
19
19
  ## Usage
20
20
 
21
- To use the gem on a string, call `read_time_words` on it.
21
+ To use the gem on a string, call `time_to_read` on it passing through the desired reading speed as an argument.
22
22
 
23
23
  Example:
24
- `some_string.read_time_words`
24
+ `some_string.read_time_words(250)`
25
25
 
26
26
  will output
27
- `2 minutes and 30 seconds to read`
27
+ `2 minutes`
28
+
29
+ Note: Times are purposly fuzzy stating Less than a minute, and only incrementing at minute increments. Please take with a grain of salt :)
28
30
 
29
31
  ## Contributing
30
32
 
31
- 1. Fork it ( http://github.com/<my-github-username>/read_time_estimator/fork )
33
+ 1. Fork it ( http://github.com/<my-github-username>/time_to_read/fork )
32
34
  2. Create your feature branch (`git checkout -b my-new-feature`)
33
35
  3. Commit your changes (`git commit -am 'Add some feature'`)
34
36
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,3 +1,3 @@
1
1
  module TimeToRead
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/time_to_read.rb CHANGED
@@ -1,14 +1,10 @@
1
- require "time_to_read/version"
1
+ # require "time_to_read/version"
2
2
 
3
3
  module TimeToRead
4
4
  module String
5
- def minutes_to_read
6
- self.split(' ').count/250.0
7
- end
8
5
 
9
- def time_to_read
10
- time = minutes_to_read
11
- answer = ''
6
+ def time_to_read(words_per_minute)
7
+ time = minutes_to_read(words_per_minute)
12
8
  if time >= 60
13
9
  hours = read_time_hours(time).to_s
14
10
  minutes = read_time_minutes(time - hours.to_i * 60).to_s
@@ -23,22 +19,25 @@ module TimeToRead
23
19
  answer.strip
24
20
  end
25
21
 
26
- def read_time_hours(time)
27
- hours = (time / 60).to_i
28
- hours_in_words(hours)
22
+ private
23
+
24
+ def minutes_to_read(words_per_minute)
25
+ self.split(' ').count/words_per_minute.to_i
29
26
  end
30
27
 
31
- def hours_in_words(hours)
32
- hours == 1 ? "#{hours} hour" : "#{hours} hours"
28
+ def read_time_hours(time)
29
+ hours = (time / 60).to_i
30
+ time_in_words(hours, 'hour')
33
31
  end
34
32
 
35
33
  def read_time_minutes(time)
36
34
  minutes = time.to_i
37
- minutes_in_words(minutes) unless minutes == 0
35
+ time_in_words(minutes, 'minute') unless minutes == 0
38
36
  end
39
37
 
40
- def minutes_in_words(minutes)
41
- minutes == 1 ? " #{minutes} minute" : " #{minutes} minutes"
38
+ def time_in_words(time_value, time_context)
39
+ time_context.to_s
40
+ time_value == 1 ? " #{time_value} #{time_context}" : " #{time_value} #{time_context}s"
42
41
  end
43
42
  end
44
43
  end
@@ -2,39 +2,32 @@ require "time_to_read"
2
2
  require 'rspec'
3
3
 
4
4
  describe "TimeToRead" do
5
- describe "minutes_to_read" do
6
- it "should output an amount of time given the length of a word" do
7
- text = "word " * 250
8
- expect(text.minutes_to_read).to eql 1.0
9
- end
10
- end
11
-
12
5
  describe "time_to_read" do
13
6
  it "returns the reading time in phrase form when there is an even number of minutes" do
14
7
  text = "word " * 500
15
- expect(text.time_to_read).to eql "2 minutes"
8
+ expect(text.time_to_read(250)).to eql "2 minutes"
16
9
  end
17
10
 
18
11
  it "returns the reading time in phrase form when there are seconds" do
19
12
  text = "word " * 625
20
- expect(text.time_to_read).to eql "2 minutes"
13
+ expect(text.time_to_read(250)).to eql "2 minutes"
21
14
  end
22
15
 
23
16
  it "returns the reading time in phrase form when read time is an hour" do
24
17
  text = "word " * 15000
25
- expect(text.time_to_read).to eql "1 hour"
18
+ expect(text.time_to_read(250)).to eql "1 hour"
26
19
  end
27
20
 
28
21
  it "returns the reading time in phrase form when read time include an hour, minutes, and seconds" do
29
22
  text = "word " * 22550
30
- expect(text.time_to_read).to eql "1 hour 30 minutes"
23
+ expect(text.time_to_read(250)).to eql "1 hour 30 minutes"
31
24
  end
32
25
  end
33
26
 
34
27
  describe "hours_in_words" do
35
28
  it "correctly pluralizes 'hour' when hours to read is greater than one" do
36
29
  text = "word " * 30000
37
- expect(text.time_to_read).to eql "2 hours"
30
+ expect(text.time_to_read(250)).to eql "2 hours"
38
31
  end
39
32
  end
40
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_to_read
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
  - Abby Ihrig