time_to_read 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83657e2ca796b3347edddaa6b0d1b61bc27041a6
4
+ data.tar.gz: 6a0b8cda9be1437afcb66bdf396698a2b5923536
5
+ SHA512:
6
+ metadata.gz: 887391409c223276f1763e278a138f00032b8ade8c3fe76ec9666fd5a9ce35329f170b537193a377820973e06eb562a0ce2b7d55c4b68542f3a71cdb4862cb4c
7
+ data.tar.gz: ffc0c5143754d472fa01799f7013996abc7d8171a3e976526ff96662c20524c752b59657dc01016d70596f8ae04e0cca530c0f7e8f126fe0cbd2f12198a1b7ce
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ time-to-read
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in read_time_estimator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Abby Ihrig
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # ReadTimeEstimator
2
+
3
+ Estimates the time to read a string of text. The gem assumes a reading speed of 250 words per minute.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'read_time_estimator'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install read_time_estimator
18
+
19
+ ## Usage
20
+
21
+ To use the gem on a string, call `read_time_words` on it.
22
+
23
+ Example:
24
+ `some_string.read_time_words`
25
+
26
+ will output
27
+ `2 minutes and 30 seconds to read`
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( http://github.com/<my-github-username>/read_time_estimator/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,49 @@
1
+ require "time_to_read/version"
2
+
3
+ module TimeToRead
4
+ module String
5
+ def minutes_to_read
6
+ self.split(' ').count/250.0
7
+ end
8
+
9
+ def time_to_read
10
+ time = minutes_to_read
11
+ answer = ''
12
+ if time >= 60
13
+ hours = read_time_hours(time).to_s
14
+ minutes = read_time_minutes(time - hours.to_i * 60).to_s
15
+ answer = hours + minutes
16
+ elsif time < 60 && time > 1
17
+ minutes = read_time_minutes(time).to_s
18
+ answer = minutes
19
+ else
20
+ answer = 'Less than a minute'
21
+ end
22
+
23
+ answer.strip
24
+ end
25
+
26
+ def read_time_hours(time)
27
+ hours = (time / 60).to_i
28
+ hours_in_words(hours)
29
+ end
30
+
31
+ def hours_in_words(hours)
32
+ hours == 1 ? "#{hours} hour" : "#{hours} hours"
33
+ end
34
+
35
+ def read_time_minutes(time)
36
+ minutes = time.to_i
37
+ minutes_in_words(minutes) unless minutes == 0
38
+ end
39
+
40
+ def minutes_in_words(minutes)
41
+ minutes == 1 ? " #{minutes} minute" : " #{minutes} minutes"
42
+ end
43
+ end
44
+ end
45
+
46
+ class String
47
+ include TimeToRead::String
48
+ end
49
+
@@ -0,0 +1,3 @@
1
+ module TimeToRead
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,40 @@
1
+ require "time_to_read"
2
+ require 'rspec'
3
+
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
+ describe "time_to_read" do
13
+ it "returns the reading time in phrase form when there is an even number of minutes" do
14
+ text = "word " * 500
15
+ expect(text.time_to_read).to eql "2 minutes"
16
+ end
17
+
18
+ it "returns the reading time in phrase form when there are seconds" do
19
+ text = "word " * 625
20
+ expect(text.time_to_read).to eql "2 minutes"
21
+ end
22
+
23
+ it "returns the reading time in phrase form when read time is an hour" do
24
+ text = "word " * 15000
25
+ expect(text.time_to_read).to eql "1 hour"
26
+ end
27
+
28
+ it "returns the reading time in phrase form when read time include an hour, minutes, and seconds" do
29
+ text = "word " * 22550
30
+ expect(text.time_to_read).to eql "1 hour 30 minutes"
31
+ end
32
+ end
33
+
34
+ describe "hours_in_words" do
35
+ it "correctly pluralizes 'hour' when hours to read is greater than one" do
36
+ text = "word " * 30000
37
+ expect(text.time_to_read).to eql "2 hours"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time_to_read/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "time_to_read"
8
+ spec.version = TimeToRead::VERSION
9
+ spec.authors = ["Abby Ihrig", "Ana Tighe", "Patrick Mounts"]
10
+ spec.email = ["abby@planetargon.com", "ana@planetargon.com", "patrick@planetargon.com"]
11
+ spec.summary = %q{Estimates amount of time required to read given content.}
12
+ spec.description = %q{Estimates amount of time required to read given content.}
13
+ spec.homepage = "https://github.com/planetargon/time_to_read.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_to_read
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abby Ihrig
8
+ - Ana Tighe
9
+ - Patrick Mounts
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-04-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '2.14'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '2.14'
57
+ description: Estimates amount of time required to read given content.
58
+ email:
59
+ - abby@planetargon.com
60
+ - ana@planetargon.com
61
+ - patrick@planetargon.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .rbenv-gemsets
68
+ - .ruby-version
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/time_to_read.rb
74
+ - lib/time_to_read/version.rb
75
+ - spec/time_to_read_spec.rb
76
+ - time_to_read.gemspec
77
+ homepage: https://github.com/planetargon/time_to_read.git
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Estimates amount of time required to read given content.
101
+ test_files:
102
+ - spec/time_to_read_spec.rb