readingtime 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,14 +5,40 @@
5
5
 
6
6
  I use [iA Writer](http://iawriter.com "iA Writer") and find the *estimated reading time* feature pretty handy. I thought it would be cool to add at the top of my blog articles on the web as [others](http://nicepaul.com "The personal blog of @nicepaul") do.
7
7
 
8
- Full credit goes to [Brian Cray](http://briancray.com/2010/04/09/estimated-reading-time-web-design "Brian Cray - Estimated Reading Time in Web Design") for explaining how to do it in PHP.
9
-
10
8
  ## How to Use
11
9
 
12
- [readingtime](http://github.com/garethrees/readingtime "Gem to estimate reading time") extends the Ruby String class, so you can call `reading_time` on any string object.
10
+ [readingtime](http://github.com/garethrees/readingtime "Gem to estimate reading time") extends the Ruby String class, so you can call `reading_time` on any `String` object.
11
+
12
+ ### Install
13
+
14
+ gem install readingtime
15
+
16
+ ### In irb
17
+
18
+ $ irb
19
+ > require 'readingtime'
20
+ => true
21
+ > @words = "Lorem ipsum dolor sit amet"
22
+ > @words.reading_time
23
+ => "0:01"
24
+
25
+ ### In Your App
26
+
27
+ <article>
28
+
29
+ <header>
30
+ <h1><%= @article.title %></h1>
31
+ <span class="readingtime">Estimated reading time – <%= @article.body.reading_time %></span>
32
+ </header>
33
+
34
+ <%= @article.body %>
35
+
36
+ </article>
37
+
38
+ And voila!
39
+
40
+ ![Screenshot of readingtime in use](https://github-screenshots.s3.amazonaws.com/readingtime-view.png "Screenshot of readingtime in use")
13
41
 
14
- ### Example
42
+ ## Thanks
15
43
 
16
- @words = "Lorem ipsum dolor sit amet"
17
- @words.reading_time
18
- => "0:01"
44
+ Credit goes to [Brian Cray](http://briancray.com/2010/04/09/estimated-reading-time-web-design "Brian Cray - Estimated Reading Time in Web Design") for explaining how to do it in PHP.
@@ -3,16 +3,17 @@ require "readingtime/core_ext"
3
3
 
4
4
  module Readingtime
5
5
 
6
- def self.minutes(words)
7
- (words / 200).floor
6
+ def self.minutes_in_seconds(words)
7
+ (words / 200).floor * 60
8
8
  end
9
9
 
10
10
  def self.seconds(words)
11
11
  (words % 200 / (200 / 60)).floor
12
12
  end
13
13
 
14
+ # TODO: Account for HH:MM:00
14
15
  def self.format_seconds(seconds)
15
- '%d:%02d' % seconds.divmod(60)
16
+ '%02d:%02d' % seconds.divmod(60)
16
17
  end
17
18
 
18
19
  end
@@ -2,7 +2,7 @@ String.class_eval do
2
2
  def reading_time
3
3
  word_size = self.calculate_size
4
4
 
5
- minutes = Readingtime.minutes(word_size)
5
+ minutes = Readingtime.minutes_in_seconds(word_size)
6
6
  seconds = Readingtime.seconds(word_size)
7
7
 
8
8
  return Readingtime.format_seconds((minutes + seconds))
@@ -1,3 +1,3 @@
1
1
  module Readingtime
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -5,30 +5,37 @@ require "readingtime"
5
5
 
6
6
 
7
7
  describe Readingtime do
8
- let(:short_text) { "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." }
9
- let(:long_text) { ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." * 100) }
8
+ let(:two_hundred_words) { ("Lorem " * 200) }
10
9
 
10
+ it "should calculate the reading time of some text" do
11
+ two_hundred_words.reading_time.should == "01:00"
12
+ end
11
13
 
12
14
  it "should calculate the length of the string input" do
13
- short_text.calculate_size.should == short_text.scan(/(\w|-)+/).size
15
+ two_hundred_words.calculate_size.should == 200
14
16
  end
15
17
 
16
-
17
18
  it "should calculate the number of minutes the reading should take" do
18
- words = short_text.calculate_size
19
- Readingtime.minutes(words).should == (words / 200).floor
19
+ words = two_hundred_words.calculate_size
20
+ Readingtime.minutes_in_seconds(words).should == 60
20
21
  end
21
22
 
22
23
  it "should calculate the remaining seconds the reading should take" do
23
- words = short_text.calculate_size
24
- Readingtime.seconds(words).should == (words % 200 / (200 / 60)).floor
24
+ words = two_hundred_words.calculate_size
25
+ Readingtime.seconds(words).should == 0
25
26
  end
26
27
 
27
- it "should format the reading time in an HH:MM format" do
28
+ it "should format the reading time in an MM:SS format" do
28
29
  Readingtime.format_seconds(3600).should == "60:00"
29
- Readingtime.format_seconds(60).should == "1:00"
30
- Readingtime.format_seconds(10).should == "0:10"
31
- Readingtime.format_seconds(1).should == "0:01"
30
+ Readingtime.format_seconds(60).should == "01:00"
31
+ Readingtime.format_seconds(10).should == "00:10"
32
+ Readingtime.format_seconds(1).should == "00:01"
32
33
  end
33
34
 
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
40
+
34
41
  end
metadata CHANGED
@@ -1,49 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: readingtime
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
4
5
  prerelease:
5
- version: 0.0.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Gareth Rees
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-27 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &4992650 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *4992650
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &4992330 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "2.6"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
35
33
  type: :development
36
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *4992330
37
36
  description: Estimates reading time of a Ruby String object
38
- email:
37
+ email:
39
38
  - gareth@garethrees.co.uk
40
39
  executables: []
41
-
42
40
  extensions: []
43
-
44
41
  extra_rdoc_files: []
45
-
46
- files:
42
+ files:
47
43
  - .gitignore
48
44
  - Gemfile
49
45
  - README.md
@@ -55,30 +51,27 @@ files:
55
51
  - spec/readingtime_spec.rb
56
52
  homepage: http://github.com/garethrees/readingtime
57
53
  licenses: []
58
-
59
54
  post_install_message:
60
55
  rdoc_options: []
61
-
62
- require_paths:
56
+ require_paths:
63
57
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
65
59
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
65
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
76
70
  requirements: []
77
-
78
71
  rubyforge_project: readingtime
79
- rubygems_version: 1.8.10
72
+ rubygems_version: 1.8.5
80
73
  signing_key:
81
74
  specification_version: 3
82
75
  summary: Estimates reading time
83
- test_files:
76
+ test_files:
84
77
  - spec/readingtime_spec.rb