scripture 0.1.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scripture.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ryan Robeson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Scripture
2
+
3
+ Provides easy access to bible verses in your application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'scripture'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install scripture
18
+
19
+ ## Usage
20
+
21
+ ### From the commandline
22
+ $ scripture lookup 'John 3:16'
23
+
24
+ ### From your code
25
+ ```ruby
26
+ require 'scripture'
27
+ verse = Scripture.get_verse('John 3:16')
28
+ puts verse
29
+ ```
30
+ ### Also supports multiple verses
31
+ John 3:16-17
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rdoc/task"
5
+ RDoc::Task.new do |rdoc|
6
+ rdoc.markup = 'tomdoc'
7
+ rdoc.rdoc_dir = 'rdoc'
8
+ rdoc.rdoc_files.include('lib/**/*.rb')
9
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'scripture'
4
+
5
+ class ScriptureCli < Thor
6
+ desc "lookup 'verse'", "Lookup the given verse and print it to the screen"
7
+ def lookup(verse)
8
+ puts Scripture.get_verse(verse)
9
+ end
10
+ end
11
+
12
+ ScriptureCli.start
@@ -0,0 +1,5 @@
1
+ require 'scripture/version'
2
+ require 'httparty'
3
+ require 'thor'
4
+ require 'scripture/bible_providers/preaching_central'
5
+ require 'scripture/actions'
@@ -0,0 +1,17 @@
1
+ module Scripture
2
+ BIBLE = BibleProvider::PreachingCentral.new
3
+
4
+ # Public: Lookup a verse of Scripture.
5
+ #
6
+ # verse - A String of the verse reference.
7
+ #
8
+ # Examples
9
+ #
10
+ # Scripture.get_verse('John 3:16')
11
+ # # => 'For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.'
12
+ #
13
+ # Returns the verse a String.
14
+ def self.get_verse(verse)
15
+ BIBLE.get_for_display(verse)
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ module Scripture
2
+ module BibleProvider
3
+ # Public: Base class for BibleProvider. Should be inherited from and overridden.
4
+ class Base
5
+ # Public: Provides a Get method for the url of the BibleProvider
6
+ attr_reader :url
7
+ # Public: Provides a Get method for the path to the verse. Usually CSS Path.
8
+ attr_reader :path_to_verse
9
+
10
+ def initialize
11
+ end
12
+
13
+ # Internal: A Mechanize agent to browse pages
14
+ #
15
+ # Returns a Mechanize object
16
+ def agent
17
+ @agent = Mechanize.new unless @agent
18
+ @agent.follow_meta_refresh = true
19
+ @agent.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'
20
+ @agent
21
+ end
22
+
23
+ # Public: The main page of the BibleProvider
24
+ #
25
+ # Returns the agent on the main page
26
+ def main_page
27
+ agent.get(@url)
28
+ end
29
+
30
+ # Internal: Searches for the verse. Must be overridden.
31
+ # May be changed to a private method. get should be
32
+ # used when acquiring a verse.
33
+ #
34
+ # verse - The verse to find.
35
+ #
36
+ # Returns the verse
37
+ def search_for(verse)
38
+ raise NotImplementedError, "#{self.class} does not implement #{__method__}"
39
+ end
40
+
41
+ # Public: Get a verse
42
+ #
43
+ # verse - The verse to get
44
+ #
45
+ # Returns the verse as a String
46
+ def get(verse)
47
+ @verse_text = search_for(verse)
48
+ end
49
+
50
+ # Public: Get a verse for display. Should be overridden for things
51
+ # such as formatting.
52
+ #
53
+ # verse - The verse to get and display
54
+ #
55
+ # Returns the verse to display
56
+ def get_for_display(verse)
57
+ get(verse)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,84 @@
1
+ #require 'httparty'
2
+ #require_relative 'base'
3
+ require 'scripture/bible_providers/base'
4
+
5
+ module Scripture
6
+ module BibleProvider
7
+ # Public: Interact with api.preachingcentral.com to provide bible
8
+ # verses
9
+ #
10
+ # Examples
11
+ # @bible_provider = Scripture::BibleProvider::PreachingCentral.new
12
+ # @bible_provider.get_for_display('John 3:16')
13
+ # # => "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
14
+ class PreachingCentral < Base
15
+ include HTTParty
16
+
17
+ # Public: Initialize the object and set the url
18
+ def initialize
19
+ @url = 'http://api.preachingcentral.com/'
20
+ end
21
+
22
+ # Internal: Search for a verse
23
+ #
24
+ # verse - A string containing the verse reference
25
+ #
26
+ # Returns the verse content
27
+ def search_for(verse)
28
+ @query = {
29
+ "passage" => verse
30
+ }
31
+
32
+ @results = self.class.get("#{@url}bible.php?", :query => @query)
33
+
34
+ @item = @results.parsed_response['bible']['range']['item']
35
+
36
+ if @item.is_a? Array
37
+ @text = @item.map do |item|
38
+ "#{item['verse']} #{item['text']} \n"
39
+ end.join('')
40
+ else
41
+ @text = @item['text']
42
+ end
43
+
44
+ @text
45
+ end
46
+
47
+ # Public: Get a verse
48
+ #
49
+ # verse - The verse to get
50
+ #
51
+ # Returns the verse formatted with self.format
52
+ def get(verse)
53
+ self.class.format(super)
54
+ end
55
+
56
+ # Public: Get a verse to display
57
+ #
58
+ # verse - The verse to get
59
+ #
60
+ # Returns the verse formatted with self.format_for_display
61
+ def get_for_display(verse)
62
+ self.class.format_for_display(super)
63
+ end
64
+
65
+ # Internal: Format a verse
66
+ #
67
+ # verse - The verse to format
68
+ #
69
+ # Returns the formatted verse
70
+ def self.format(verse)
71
+ verse.gsub(/\n/, '<br />')
72
+ end
73
+
74
+ # Internal: Format a verse for display
75
+ #
76
+ # verse - The verse to format
77
+ #
78
+ # Returns the formatted verse
79
+ def self.format_for_display(verse)
80
+ verse.gsub('<br />', "\n")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Scripture
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/scripture/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ryan Robeson"]
6
+ gem.email = ["ryan.robeson@gmail.com"]
7
+ gem.description = %q{}
8
+ gem.summary = %q{A simple gem for acquiring bible verses.}
9
+ gem.homepage = "https://github.com/ryan-robeson/scripture-gem"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "scripture"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Scripture::VERSION
17
+
18
+ # Dependencies
19
+ %w[thor httparty].each do |g|
20
+ gem.add_dependency g
21
+ end
22
+
23
+ # Development Dependencies
24
+ %w[rake rdoc].each do |g|
25
+ gem.add_development_dependency g
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scripture
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Robeson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70236014151940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70236014151940
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ requirement: &70236014151540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70236014151540
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70236014151080 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70236014151080
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70236014150660 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70236014150660
58
+ description: ''
59
+ email:
60
+ - ryan.robeson@gmail.com
61
+ executables:
62
+ - scripture
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/scripture
72
+ - lib/scripture.rb
73
+ - lib/scripture/actions.rb
74
+ - lib/scripture/bible_providers/base.rb
75
+ - lib/scripture/bible_providers/preaching_central.rb
76
+ - lib/scripture/version.rb
77
+ - scripture.gemspec
78
+ homepage: https://github.com/ryan-robeson/scripture-gem
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 2435030535799128672
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 2435030535799128672
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.10
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: A simple gem for acquiring bible verses.
108
+ test_files: []