votd 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -7,7 +7,6 @@ rvm:
7
7
  notifications:
8
8
  email:
9
9
  recipients:
10
- - beakr@ninjanizr.com
11
10
  - doctorbh@ninjanizr.com
12
11
  - main@seven7.flowdock.com
13
12
  on_success: always
data/CHANGELOG.md CHANGED
@@ -1,9 +1,19 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- Current Iteration
4
+ 2.1.3
5
5
  -----------------
6
6
 
7
+ *April 5, 2012*
8
+
9
+ * Reorganized Helper modules (used internally only)
10
+ * Minor bug fixes
11
+
12
+ 2.1.2
13
+ -----------------
14
+
15
+ *April 4, 2012*
16
+
7
17
  * Added custom exception type `Votd::VotdError`
8
18
  * Added `Votd::Helper` module to provide common helper methods to all modules
9
19
  * Cleaned up command-line version to wrap text properly
@@ -16,7 +26,7 @@ Current Iteration
16
26
  2.1.1
17
27
  -----
18
28
 
19
- *March 31, 2010*
29
+ *March 31, 2012*
20
30
 
21
31
  * VotD will now return a default scripture of John 3:16 in KJV if there's
22
32
  any error enountered when accessing the VotD from the source server.
data/bin/votd CHANGED
@@ -4,8 +4,9 @@
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
5
 
6
6
  require 'votd'
7
+ require 'votd/helper/command_line'
7
8
 
8
- include Votd::Helper
9
+ include Votd::Helper::CommandLine
9
10
 
10
11
  votd = Votd::BibleGateway.new
11
12
  #votd = Votd::NetBible.new
@@ -20,4 +21,4 @@ puts word_wrap(votd.to_text, LINE_WIDTH)
20
21
  if votd.copyright
21
22
  puts "\n"
22
23
  puts banner(LINE_WIDTH) { word_wrap(votd.copyright, LINE_WIDTH) }
23
- end
24
+ end
data/lib/votd/base.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'votd/helper/text'
2
+
1
3
  module Votd
2
4
  # This is the base class that all Votd lookup modules inherit from.
3
5
  # It provides default values for the Votd in the event of lookup failure.
@@ -146,33 +148,5 @@ module Votd
146
148
  @copyright = nil
147
149
  end
148
150
 
149
- # Removes HTML tags from the given text
150
- # @param [String] text the text you want to strip HTML tags from
151
- # @return [String]
152
- def strip_html_tags(text)
153
- text.gsub(/<\/?[^>]*>/, '')
154
- end
155
-
156
- # Prepends '...' if first letter is not a capital letter
157
- # @param [String] the text to process
158
- # @return [String]
159
- def clean_verse_start(text)
160
- text.sub(/^([a-z])/, '...\1')
161
- end
162
-
163
- # Appends '...' if verse ends abruptly
164
- # @param [String] the text to process
165
- # @return [String]
166
- def clean_verse_end(text)
167
- case text
168
- when /[a-zA=Z]$/ # no ending "."
169
- text << '...'
170
- when /[,;]$/
171
- text.sub!(/,$/, '...') # ends with "," or ";"
172
- else
173
- text
174
- end
175
- text
176
- end
177
151
  end
178
152
  end
@@ -1,4 +1,5 @@
1
1
  require 'feedzirra'
2
+ require 'votd/helper/text'
2
3
 
3
4
  module Votd
4
5
  # Retrieves a Verse of the Day from biblegateway.com using a variety
@@ -53,18 +54,18 @@ module Votd
53
54
  # @return [String]
54
55
  def clean_text(text)
55
56
  text = strip_html_quote_entities(text)
56
- text = strip_html_tags(text)
57
+ text = Helper::Text.strip_html_tags(text)
57
58
  text = strip_copyright_text(text)
58
59
  text.strip!
59
- text = clean_verse_start(text)
60
- text = clean_verse_end(text)
60
+ text = Helper::Text.clean_verse_start(text)
61
+ text = Helper::Text.clean_verse_end(text)
61
62
  end
62
63
 
63
64
  # Extracts copyright tag from the Bible text
64
65
  # @return [String]
65
66
  def get_copyright(text)
66
67
  text = strip_html_quote_entities(text)
67
- text = strip_html_tags(text)
68
+ text = Helper::Text.strip_html_tags(text)
68
69
  text.match(@regex_copyright_text)[1]
69
70
  end
70
71
 
@@ -0,0 +1,38 @@
1
+ module Votd
2
+ module Helper
3
+ # This module contains helper methods that support the
4
+ # command-line application
5
+ module CommandLine
6
+ extend self
7
+ # Generates a text banner suitable for displaying from a command-line
8
+ # utility, for example. Use with a block.
9
+ # @example
10
+ # banner(20) { "My Banner" }
11
+ #
12
+ # ->
13
+ # ====================
14
+ # My Banner
15
+ # ====================
16
+ # @param [Integer] line_width number of columns for width
17
+ # @return [String] the banner text
18
+ def banner(line_width=40)
19
+ banner_text = "=" * line_width
20
+ banner_text << "\n"
21
+ banner_text << yield.center(line_width)
22
+ banner_text << "\n"
23
+ banner_text << "=" * line_width
24
+ banner_text
25
+ end
26
+
27
+ # Word-wraps text to the specified column width.
28
+ # @param [String] text the text to be wrapped
29
+ # @param [Integer] line_width column width
30
+ # @return [String] wrapped text
31
+ def word_wrap(text, line_width=40)
32
+ text.split("\n").collect do |line|
33
+ line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
34
+ end * "\n"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ module Votd
2
+ # This module provides various helper methods used throughout the
3
+ # codebase.
4
+ module Helper
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ module Votd
2
+ module Helper
3
+ # This module contains helper methods that support the
4
+ # VotD text parsing.
5
+ module Text
6
+ extend self
7
+ # Removes HTML tags from the given text
8
+ # @param [String] text the text you want to strip HTML tags from
9
+ # @return [String]
10
+ def strip_html_tags(text)
11
+ text.gsub(/<\/?[^>]*>/, '')
12
+ end
13
+
14
+ # Prepends '...' if first letter is not a capital letter
15
+ # @param [String] the text to process
16
+ # @return [String]
17
+ def clean_verse_start(text)
18
+ text.sub(/^([a-z])/, '...\1')
19
+ end
20
+
21
+ # Appends '...' if verse ends abruptly
22
+ # @param [String] the text to process
23
+ # @return [String]
24
+ def clean_verse_end(text)
25
+ case text
26
+ when /[a-zA-Z]$/ # no ending "."
27
+ text << '...'
28
+ when /[,;]$/
29
+ text.sub!(/[,;]$/, '...') # ends with "," or ";"
30
+ else
31
+ text
32
+ end
33
+ text
34
+ end
35
+
36
+ end
37
+ end
38
+ end
data/lib/votd/netbible.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'votd/helper/text'
2
+
1
3
  module Votd
2
4
  # Retrieves a Verse of the Day from http://bible.org using the NETBible
3
5
  # translation.
@@ -37,7 +39,8 @@ module Votd
37
39
  @reference = "#{bookname} #{chapter}:#{verse_numbers.join("-")}"
38
40
 
39
41
  # build the text
40
- text = strip_html_tags(verses.join(" "))
42
+ #text = strip_html_tags(verses.join(" "))
43
+ text = Helper::Text.strip_html_tags(verses.join(" "))
41
44
  text = clean_verse_start(text)
42
45
  text = clean_verse_end(text)
43
46
 
data/lib/votd/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Votd
2
2
  # Gem version number
3
- VERSION = "2.1.2"
3
+ VERSION = "2.1.3"
4
4
  end
data/lib/votd.rb CHANGED
@@ -7,8 +7,8 @@ require "httparty"
7
7
  module Votd
8
8
  end
9
9
 
10
+ require "votd/helper/text"
10
11
  require "votd/version"
11
- require "votd/helper"
12
12
  require "votd/votd_error"
13
13
  require "votd/base"
14
14
  require "votd/bible_gateway"
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'votd/helper/command_line'
2
3
 
3
- include Votd::Helper
4
+ include Votd::Helper::CommandLine
4
5
 
5
- describe Votd::Helper do
6
+ describe Votd::Helper::CommandLine do
6
7
  describe "#banner" do
7
8
  it "prints a banner wrapped at the correct location" do
8
9
  banner(6){ "foo" }.should == "======\n foo \n======"
@@ -14,6 +15,5 @@ describe Votd::Helper do
14
15
  text = "The quick brown fox jumps over the lazy dog."
15
16
  word_wrap(text, 20).should == "The quick brown fox\njumps over the lazy\ndog."
16
17
  end
17
-
18
18
  end
19
- end
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'spec_helper'
2
+ describe Votd::Helper do
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ include Votd::Helper::Text
4
+
5
+ describe Votd::Helper::Text do
6
+ describe ".strip_html_tags" do
7
+ it "removes HTML tags from a given string" do
8
+ text = %q[<p>The <span name="foo">quick</span> brown fox.</p><br />]
9
+ strip_html_tags(text).should == "The quick brown fox."
10
+ end
11
+ end
12
+
13
+ describe ".clean_verse_start" do
14
+ it "prepends '...' if the first letter is not a capital letter" do
15
+ text = "for God so loved"
16
+ clean_verse_start(text).should == "...for God so loved"
17
+ end
18
+ end
19
+
20
+ describe ".clean_verse_end" do
21
+ it "appends '...' if the verse ends without a period" do
22
+ text = "For God so loved"
23
+ clean_verse_end(text).should == "For God so loved..."
24
+ end
25
+
26
+ it "appends '...' if the verse ends in a ',' or ';'" do
27
+ ["loved,", "loved;"].each do |text|
28
+ clean_verse_end(text).should == "loved..."
29
+ end
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: votd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-04 00:00:00.000000000 Z
13
+ date: 2012-04-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -181,7 +181,9 @@ files:
181
181
  - lib/votd.rb
182
182
  - lib/votd/base.rb
183
183
  - lib/votd/bible_gateway.rb
184
- - lib/votd/helper.rb
184
+ - lib/votd/helper/command_line.rb
185
+ - lib/votd/helper/helper.rb
186
+ - lib/votd/helper/text.rb
185
187
  - lib/votd/netbible.rb
186
188
  - lib/votd/version.rb
187
189
  - lib/votd/votd_error.rb
@@ -204,7 +206,9 @@ files:
204
206
  - spec/fixtures/netbible/netbible_with_partial.json
205
207
  - spec/lib/votd/base_spec.rb
206
208
  - spec/lib/votd/bible_gateway_spec.rb
207
- - spec/lib/votd/helper_spec.rb
209
+ - spec/lib/votd/helper/command_line_spec.rb
210
+ - spec/lib/votd/helper/helper_spec.rb
211
+ - spec/lib/votd/helper/text_spec.rb
208
212
  - spec/lib/votd/netbible_spec.rb
209
213
  - spec/lib/votd/version_spec.rb
210
214
  - spec/lib/votd/votd_error_spec.rb
@@ -256,7 +260,9 @@ test_files:
256
260
  - spec/fixtures/netbible/netbible_with_partial.json
257
261
  - spec/lib/votd/base_spec.rb
258
262
  - spec/lib/votd/bible_gateway_spec.rb
259
- - spec/lib/votd/helper_spec.rb
263
+ - spec/lib/votd/helper/command_line_spec.rb
264
+ - spec/lib/votd/helper/helper_spec.rb
265
+ - spec/lib/votd/helper/text_spec.rb
260
266
  - spec/lib/votd/netbible_spec.rb
261
267
  - spec/lib/votd/version_spec.rb
262
268
  - spec/lib/votd/votd_error_spec.rb
data/lib/votd/helper.rb DELETED
@@ -1,36 +0,0 @@
1
- module Votd
2
- # This module provides various helper methods used throughout the
3
- # codebase.
4
- module Helper
5
- # Generates a text banner suitable for displaying from a command-line
6
- # utility, for example. Use with a block.
7
- # @example
8
- # banner(20) { "My Banner" }
9
- #
10
- # ->
11
- # ====================
12
- # My Banner
13
- # ====================
14
- # @param [Integer] line_width number of columns for width
15
- # @return [String] the banner text
16
- def banner(line_width=40)
17
- banner_text = "=" * line_width
18
- banner_text << "\n"
19
- banner_text << yield.center(line_width)
20
- banner_text << "\n"
21
- banner_text << "=" * line_width
22
- banner_text
23
- end
24
-
25
- # Word-wraps text to the specified column width.
26
- # @param [String] text the text to be wrapped
27
- # @param [Integer] line_width column width
28
- # @return [String] wrapped text
29
- def word_wrap(text, line_width=40)
30
- text.split("\n").collect do |line|
31
- line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
32
- end * "\n"
33
- end
34
-
35
- end
36
- end