readingtime 0.0.5 → 0.1.0
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/lib/readingtime/core_ext.rb +9 -3
- data/lib/readingtime/version.rb +1 -1
- data/lib/readingtime.rb +4 -0
- data/spec/readingtime_spec.rb +7 -5
- metadata +5 -5
data/lib/readingtime/core_ext.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
String.class_eval do
|
2
|
-
def reading_time
|
2
|
+
def reading_time(options = {})
|
3
|
+
format_options = options[:format] || :basic
|
4
|
+
|
3
5
|
word_size = self.calculate_size
|
4
|
-
|
5
6
|
minutes = Readingtime.minutes_in_seconds(word_size)
|
6
7
|
seconds = Readingtime.seconds(word_size)
|
7
8
|
|
8
|
-
|
9
|
+
case format_options
|
10
|
+
when :basic
|
11
|
+
Readingtime.format_seconds((minutes + seconds))
|
12
|
+
when :long
|
13
|
+
Readingtime.format_words((minutes + seconds))
|
14
|
+
end
|
9
15
|
|
10
16
|
end
|
11
17
|
|
data/lib/readingtime/version.rb
CHANGED
data/lib/readingtime.rb
CHANGED
data/spec/readingtime_spec.rb
CHANGED
@@ -6,9 +6,11 @@ require "readingtime"
|
|
6
6
|
|
7
7
|
describe Readingtime do
|
8
8
|
let(:two_hundred_words) { ("Lorem " * 200) }
|
9
|
+
let(:three_hundred_words) { ("Lorem " * 300) }
|
9
10
|
|
10
11
|
it "should calculate the reading time of some text" do
|
11
12
|
two_hundred_words.reading_time.should == "01:00"
|
13
|
+
three_hundred_words.reading_time.should == "01:33"
|
12
14
|
end
|
13
15
|
|
14
16
|
it "should calculate the length of the string input" do
|
@@ -32,10 +34,10 @@ describe Readingtime do
|
|
32
34
|
Readingtime.format_seconds(1).should == "00:01"
|
33
35
|
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
it "should accept an options hash to format the output" do
|
38
|
+
two_hundred_words.reading_time(:format => :basic).should == "01:00"
|
39
|
+
two_hundred_words.reading_time(:format => :long).should == "1 minutes and 0 seconds"
|
40
|
+
three_hundred_words.reading_time(:format => :long).should == "1 minutes and 33 seconds"
|
41
|
+
end
|
40
42
|
|
41
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readingtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-30 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &4989810 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *4989810
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &4989560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '2.6'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *4989560
|
36
36
|
description: Estimates reading time of a Ruby String object
|
37
37
|
email:
|
38
38
|
- gareth@garethrees.co.uk
|