readingtime 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- return Readingtime.format_seconds((minutes + seconds))
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
 
@@ -1,3 +1,3 @@
1
1
  module Readingtime
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/readingtime.rb CHANGED
@@ -16,4 +16,8 @@ module Readingtime
16
16
  '%02d:%02d' % seconds.divmod(60)
17
17
  end
18
18
 
19
+ def self.format_words(seconds)
20
+ '%d minutes and %d seconds' % seconds.divmod(60)
21
+ end
22
+
19
23
  end
@@ -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
- # it "should accept an options hash to format the output" do
36
- # short_text.reading_time(:format => :basic).should == "0:23"
37
- # short_text.reading_time(:format => :short).should == "23 seconds"
38
- # short_text.reading_time(:format => :long).should == "0 minutes and 23 seconds"
39
- # end
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.5
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: &4992650 !ruby/object:Gem::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: *4992650
24
+ version_requirements: *4989810
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &4992330 !ruby/object:Gem::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: *4992330
35
+ version_requirements: *4989560
36
36
  description: Estimates reading time of a Ruby String object
37
37
  email:
38
38
  - gareth@garethrees.co.uk