read-time 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/read-time.rb +57 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1af0628ed42c950217432c52dd50129d684cf9f
|
4
|
+
data.tar.gz: 2db889fcff39e1075e7ae0a79881ccad0cfe7f8d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eae2eec380bcc2c73f789600638a7950cfc695e3e40d49f5d60af844d652719886843e7a047f524403306e4c2cc45e41bfe54532be3c51f9bcb117e8a3b9cc40
|
7
|
+
data.tar.gz: 3bbc7ba8045a310a1f3389278140c3f1b5042e5896abb1bd20fce1e0df5a2f1cf1a8f003acbc9567ba642be6f9123ab70cadd17e0cf708c666fb1008ba373adf
|
data/lib/read-time.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module ReadTime
|
2
|
+
def readtime(options = {})
|
3
|
+
reading_speed = (options[:reading_speed] || ReadTime.config.reading_speed).to_f
|
4
|
+
format = options[:format] || ReadTime.config.format
|
5
|
+
word_count = scan(/[\w-]+/).size
|
6
|
+
num = ((word_count / reading_speed) * 60).ceil
|
7
|
+
|
8
|
+
minutes = num / 60
|
9
|
+
seconds = num - (minutes * 60)
|
10
|
+
|
11
|
+
case format
|
12
|
+
when :default
|
13
|
+
min = (num / 60.0).ceil
|
14
|
+
"#{min} minute read"
|
15
|
+
when :long
|
16
|
+
if seconds.zero?
|
17
|
+
"#{minutes} minute read"
|
18
|
+
elsif minutes.zero?
|
19
|
+
"#{seconds} second read"
|
20
|
+
else
|
21
|
+
"#{minutes} minute #{seconds} second read"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
min = (num / 60.0).ceil
|
25
|
+
"#{min} minute read"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_writer :config
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.config
|
34
|
+
@config ||= Configuration.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.reset_config
|
38
|
+
@config = Configuration.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.configure
|
42
|
+
yield(config)
|
43
|
+
end
|
44
|
+
|
45
|
+
class Configuration
|
46
|
+
attr_accessor :format, :reading_speed
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@format = :default
|
50
|
+
@reading_speed = 275 # WPM (words per minute)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class String
|
56
|
+
include ReadTime
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: read-time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Deepak Mahakale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: ReadTime estimates the time required to read the article.
|
28
|
+
email: deepakmahakale@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/read-time.rb
|
34
|
+
homepage: http://rubygems.org/gems/read-time
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 1.3.1
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.4.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Time required to read an article
|
58
|
+
test_files: []
|