scriptura 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ca9e6019ef5c673caa81c0091b1e9367f021edc
4
- data.tar.gz: 8f4bf8c9d1e39d13356639421c26f2716f9d5908
3
+ metadata.gz: f0044ece919fa1f8adacbf9692fc1466bb5467d8
4
+ data.tar.gz: f96700adfc6c802c81bed1ba6fdf1e6b6c90a6cf
5
5
  SHA512:
6
- metadata.gz: 0b5217b85c0d71de9d02b437fcae979206a52f8cecbc045a7c2341e9786423f9f76b850649a566d6618930bad4e0c9ebe456f7bdefb98a9e5085a92de9c3c4b4
7
- data.tar.gz: dbd2018a3af992250bb36c0671365ad6cec21d269e7f9ce51aa8641f067eda8215b79d08d15d66c4e6fa3e65416665c482e39b7c2b05d91a2e02c40d975889f2
6
+ metadata.gz: 034c0937de8ffcf99bbe5a96d73533f540f74150d1e79fb997f23bd01373d80325847b49f5f57291cb7aa1f355b0ec60b3aedf83d0d05888e729b60cc884e126
7
+ data.tar.gz: 9c833b5ecad6d4ee8bbe1434c0598e907b7f24f1316e7e565252515b304e85333a57a7cf9eaaeb7f27b9826b231e7e70452629cd1827cf586fc4385875d7ec4b
@@ -2,6 +2,9 @@ require 'yaml'
2
2
 
3
3
  module Scriptura
4
4
  module Scripture
5
+ HOME_PATH = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
6
+ METADATA_FILE = File.join(HOME_PATH, 'lib', 'scriptura', 'metadata.yml')
7
+
5
8
  def self.old_testament_books
6
9
  books = []
7
10
  (1..39).each do |book_number|
@@ -27,9 +30,7 @@ module Scriptura
27
30
  end
28
31
 
29
32
  def self.metadata
30
- @metadata ||= begin
31
- YAML.load_file('lib/scriptura/metadata.yml')
32
- end
33
+ @metadata ||= YAML.load_file(METADATA_FILE)
33
34
  end
34
35
 
35
36
  def self.find_book_hash attribute, value
@@ -13,13 +13,13 @@ module Scriptura
13
13
 
14
14
  def self.find_by_name(name)
15
15
  hash = Scripture.find_book_hash(:name, name)
16
- fail "Book by the name #{name} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
16
+ fail DoesNotExist, "Book by the name #{name} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
17
17
  new(hash['number'])
18
18
  end
19
19
 
20
20
  def self.find(string_id)
21
21
  hash = Scripture.find_book_hash(:string_id, string_id)
22
- fail "Book by the string_id #{string_id} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
22
+ fail DoesNotExist, "Book by the string_id #{string_id} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
23
23
  new(hash['number'])
24
24
  end
25
25
 
@@ -8,13 +8,8 @@ module Scriptura
8
8
  alias_method :number, :verse_number
9
9
 
10
10
  def initialize(*args)
11
- case
12
- when args.count == 1 && args[0].is_a?(Fixnum)
13
- fail ArgumentError, 'normalized value of scripture verse cannot be converted to an integer' unless args[0].respond_to?(:to_i)
14
- book_number, chapter_number, verse_number = de_normalize(args[0])
15
- when args.count == 3
16
- book_number, chapter_number, verse_number = args
17
- end
11
+ book_number, chapter_number, verse_number = extract_arguments(args)
12
+
18
13
  @scripture_chapter = ScriptureChapter.new(book_number, chapter_number)
19
14
  @scripture_book = @scripture_chapter.scripture_book
20
15
  fail ArgumentError, 'verse number cannot be converted to an integer' unless verse_number.respond_to?(:to_i)
@@ -39,6 +34,18 @@ module Scriptura
39
34
 
40
35
  private
41
36
 
37
+ def extract_arguments args
38
+ case args.count
39
+ when 1
40
+ fail ArgumentError, 'normalized value of scripture verse cannot be converted to an integer' unless args[0].respond_to?(:to_i)
41
+ book_number, chapter_number, verse_number = de_normalize(args[0].to_i)
42
+ when 3
43
+ book_number, chapter_number, verse_number = args
44
+ else
45
+ fail ArgumentError, 'wrong number of arguments! The arguments should either be one normalized value for the verse or 3 separate book, chapter, verse numbers'
46
+ end
47
+ end
48
+
42
49
  def de_normalize(number)
43
50
  quotient, verse_number = number.divmod(1000)
44
51
  book_number, chapter_number = quotient.divmod(1000)
@@ -1,5 +1,5 @@
1
1
  module Scriptura
2
2
  module Version
3
- STRING = '0.0.3'
3
+ STRING = '0.0.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scriptura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gagan Awhad