readingtime 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -37,7 +37,7 @@ I use [iA Writer](http://iawriter.com "iA Writer") and find the *estimated readi
37
37
 
38
38
  And voila!
39
39
 
40
- ![Screenshot of readingtime in use](https://github-screenshots.s3.amazonaws.com/readingtime-view.png "Screenshot of readingtime in use")
40
+ ![Screenshot of readingtime in use](https://s3.amazonaws.com/github-screenshots/garethrees/readingtime/readingtime-view.png "Screenshot of readingtime in use")
41
41
 
42
42
  ### Options
43
43
 
@@ -1,16 +1,18 @@
1
1
  String.class_eval do
2
2
  def reading_time(options = {})
3
- format_options = options[:format] || :basic
3
+ format_options = options[:format] || :basic
4
4
 
5
5
  word_size = self.calculate_size
6
6
  minutes = Readingtime.minutes_in_seconds(word_size)
7
7
  seconds = Readingtime.seconds(word_size)
8
8
 
9
9
  case format_options
10
- when :basic
11
- Readingtime.format_seconds((minutes + seconds))
12
- when :long
13
- Readingtime.format_words((minutes + seconds))
10
+ when :basic
11
+ Readingtime.format_seconds((minutes + seconds))
12
+ when :long
13
+ Readingtime.format_words((minutes + seconds))
14
+ when :approx
15
+ Readingtime.format_approx((minutes + seconds))
14
16
  end
15
17
 
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module Readingtime
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/readingtime.rb CHANGED
@@ -20,4 +20,12 @@ module Readingtime
20
20
  '%d minutes and %d seconds' % seconds.divmod(60)
21
21
  end
22
22
 
23
+ def self.format_approx(seconds)
24
+ if seconds > 59
25
+ '%d minutes' % (seconds.to_f/60).round
26
+ else
27
+ '%d seconds' % seconds
28
+ end
29
+ end
30
+
23
31
  end
@@ -7,6 +7,7 @@ require "readingtime"
7
7
  describe Readingtime do
8
8
  let(:two_hundred_words) { ("Lorem " * 200) }
9
9
  let(:three_hundred_words) { ("Lorem " * 300) }
10
+ let(:ten_words) { ("Lorem " * 10) }
10
11
 
11
12
  it "should calculate the reading time of some text" do
12
13
  two_hundred_words.reading_time.should == "01:00"
@@ -37,7 +38,13 @@ describe Readingtime do
37
38
  it "should accept an options hash to format the output" do
38
39
  two_hundred_words.reading_time(:format => :basic).should == "01:00"
39
40
  two_hundred_words.reading_time(:format => :long).should == "1 minutes and 0 seconds"
41
+ two_hundred_words.reading_time(:format => :approx).should == "1 minutes"
40
42
  three_hundred_words.reading_time(:format => :long).should == "1 minutes and 33 seconds"
43
+ three_hundred_words.reading_time(:format => :approx).should == "2 minutes"
44
+ end
45
+
46
+ it "should return a time in seconds when using approx with time less than 1 minute" do
47
+ ten_words.reading_time(:format => :approx).should == "3 seconds"
41
48
  end
42
49
 
43
50
  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.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-30 00:00:00.000000000Z
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &5050120 !ruby/object:Gem::Requirement
16
+ requirement: &70347145149640 !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: *5050120
24
+ version_requirements: *70347145149640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &5049870 !ruby/object:Gem::Requirement
27
+ requirement: &70347145149140 !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: *5049870
35
+ version_requirements: *70347145149140
36
36
  description: Estimates reading time of a Ruby String object
37
37
  email:
38
38
  - gareth@garethrees.co.uk
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  requirements: []
71
71
  rubyforge_project: readingtime
72
- rubygems_version: 1.8.5
72
+ rubygems_version: 1.8.15
73
73
  signing_key:
74
74
  specification_version: 3
75
75
  summary: Estimates reading time