readingtime 0.3.3 → 0.4.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.
@@ -4,9 +4,20 @@ Dir[File.dirname(__FILE__) + '/readingtime/*.rb'].each do |file|
4
4
  end
5
5
 
6
6
  module Readingtime
7
- #TODO: move this to a configuration object
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configure
12
+ yield(configuration)
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
8
19
  def self.reading_speed
9
- 200
20
+ configuration.reading_speed
10
21
  end
11
22
 
12
23
  def self.hms(secs)
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ module Readingtime
3
+ class Configuration
4
+ attr_accessor :reading_speed
5
+
6
+ def initialize
7
+ @reading_speed = 200
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Readingtime
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ path = File.expand_path(File.dirname(__FILE__) + "/../../lib/")
3
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
4
+ require "readingtime"
5
+
6
+ describe Readingtime::Configuration do
7
+
8
+ describe '.new' do
9
+ it 'sets the default reading_speed' do
10
+ subject.reading_speed.should == 200
11
+ end
12
+ end
13
+
14
+ describe '#reading_speed' do
15
+ it 'returns the reading_speed' do
16
+ subject.reading_speed.should == 200
17
+ end
18
+ end
19
+
20
+ describe '#reading_speed=' do
21
+ it 'sets the reading_speed' do
22
+ subject.reading_speed = 250
23
+ subject.reading_speed.should == 250
24
+ end
25
+ end
26
+
27
+ end
@@ -3,7 +3,6 @@ path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
3
3
  $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
4
4
  require "readingtime"
5
5
 
6
-
7
6
  describe Readingtime do
8
7
  let(:two_hundred_words) { ("Lorem " * 200) }
9
8
  let(:three_hundred_words) { ("Lorem " * 300) }
@@ -66,4 +65,20 @@ describe Readingtime do
66
65
  two_hundred_words.reading_time(:format => :raw).should == [0, 1, 0]
67
66
  end
68
67
 
68
+ it 'should use the default reading speed from configuration' do
69
+ Readingtime.reading_speed.should == 200
70
+ end
71
+
72
+ it "should use reading speed from configuration" do
73
+ Readingtime.configure do |config|
74
+ config.reading_speed = 250
75
+ end
76
+
77
+ Readingtime.reading_speed.should == 250
78
+
79
+ Readingtime.configure do |config|
80
+ config.reading_speed = 200
81
+ end
82
+ end
83
+
69
84
  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.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-13 00:00:00.000000000 Z
12
+ date: 2016-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -58,10 +58,12 @@ files:
58
58
  - Rakefile
59
59
  - lib/readingtime.rb
60
60
  - lib/readingtime/calculator.rb
61
+ - lib/readingtime/configuration.rb
61
62
  - lib/readingtime/core_ext.rb
62
63
  - lib/readingtime/version.rb
63
64
  - readingtime.gemspec
64
65
  - spec/readingtime/calculator_spec.rb
66
+ - spec/readingtime/configuration_spec.rb
65
67
  - spec/readingtime_spec.rb
66
68
  homepage: http://github.com/garethrees/readingtime
67
69
  licenses: []