Module: StandardWorks

Defined in:
lib/standard_works.rb,
lib/standard_works/version.rb,
lib/standard_works/file_helper.rb,
lib/standard_works/abbreviations.rb

Overview

Extension for Abbreviations

Constant Summary collapse

VERSION =
'0.0.2'.freeze
OPTIONS =
{ symbol_keys: true, mode: :compat }.freeze
LOCATION =
'lib/standard_works/source/'.freeze

Class Method Summary collapse

Class Method Details

.abrvObject

rubocop:disable Metrics/MethodLength



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/standard_works/abbreviations.rb', line 10

def self.abrv
  {
    # This one Is Opposite due to how the references are stored
    'Doctrine and Covenants' => 'D&C',

    # POG
    'Abr.' => 'Abraham',
    'JS-M' => 'Joseph Smith—Matthew',
    'JS-H' => 'Joseph Smith—History',
    'A of F' => 'Articles of Faith',

    # Others
    'Gen.' => 'Genesis',
    'Ex.' => 'Exodus',
    'Lev.' => 'Leviticus',
    'Num.' => 'Numbers',
    'Deut.' => 'Deuteronomy',
    'Josh.' => 'Joshua',
    'Judg.' => 'Judges',
    '1 Sam.' => '1 Samuel',
    '2 Sam.' => '2 Samuel',
    '1 Kgs.' => '1 Kings',
    '2 Kgs.' => '2 Kings',
    '1 Chr.' => '1 Chronicles',
    '2 Chr.' => '2 Chronicles',
    'Neh.' => 'Nehemiah',
    'Esth.' => 'Esther',
    'Ps.' => 'Psalms',
    'Prov.' => 'Proverbs',
    'Eccl.' => 'Ecclesiastes',
    'Song.' => 'Song of Solomon',
    'Isa.' => 'Isaiah',
    'Jer.' => 'Jeremiah',
    'Lam.' => 'Lamentations',
    'Ezek.' => 'Ezekiel',
    'Dan.' => 'Daniel',
    'Obad.' => 'Obadiah',
    'Hab.' => 'Habakkuk',
    'Zeph.' => 'Zephaniah',
    'Hag.' => 'Haggai',
    'Zech.' => 'Zechariah',
    'Mal.' => 'Malachi',
    'Matt.' => 'Matthew',
    'Rom.' => 'Romans',
    '1 Cor.' => '1 Corinthians',
    '2 Cor.' => '2 Corinthians',
    'Gal.' => 'Galatians',
    'Eph.' => 'Ephesians',
    'Philip.' => 'Philippians',
    'Col.' => 'Colossians',
    '1 Thes.' => '1 Thessalonians',
    '2 Thes.' => '2 Thessalonians',
    '1 Tim.' => '1 Timothy',
    '2 Tim.' => '2 Timothy',
    'Philem.' => 'Philemon',
    'Heb.' => 'Hebrews',
    '1 Pet.' => '1 Peter',
    '2 Pet.' => '2 Peter',
    '1 Jn.' => '1 John',
    '2 Jn.' => '2 John',
    '3 Jn.' => '3 John',
    'Rev.' => 'Revelation',
    '1 Ne.' => '1 Nephi',
    '2 Ne.' => '2 Nephi',
    'W of M' => 'Words of Mormon',
    'Hel.' => 'Helaman',
    '3 Ne.' => '3 Nephi',
    '4 Ne.' => '4 Nephi',
    'Morm.' => 'Mormon',
    'Moro.' => 'Moroni'
  }
end

.add_reference(verse) ⇒ Object



25
26
27
# File 'lib/standard_works/file_helper.rb', line 25

def self.add_reference(verse)
  @references[verse[:reference]] = verse[:text]
end

.allObject



14
15
16
# File 'lib/standard_works.rb', line 14

def self.all
  references
end

.booksObject



39
40
41
42
43
44
45
46
47
# File 'lib/standard_works/file_helper.rb', line 39

def self.books
  [
    'book-of-mormon',
    'doctrine-and-covenants',
    'new-testament',
    'old-testament',
    'pearl-of-great-price'
  ]
end

.chapter_verses(power) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/standard_works/file_helper.rb', line 29

def self.chapter_verses(power)
  # Get down to Verses
  power[:books].each do |sub_book|
    sub_book[:chapters].each do |chapter|
      chapter[:verses].each { |verse| add_reference(verse) }
    end
  end
  # And turn it into the main reference
end

.clearObject



10
11
12
# File 'lib/standard_works.rb', line 10

def self.clear
  @references = nil
end

.expand(term) ⇒ Object



3
4
5
6
7
# File 'lib/standard_works/abbreviations.rb', line 3

def self.expand(term)
  key = abrv.keys.find { |x| term.include? x }
  return term unless key
  term.gsub(key, abrv[key])
end

.load_booksObject



9
10
11
12
13
14
15
16
17
# File 'lib/standard_works/file_helper.rb', line 9

def self.load_books
  @references = {}
  books.each do |book|
    power = read book

    chapter_verses(power) if power.key? :books
    sections(power) if power.key? :sections
  end
end

.lookup(term) ⇒ Object



22
23
24
25
26
27
# File 'lib/standard_works.rb', line 22

def self.lookup(term)
  term = expand(term)
  verse = references.dig(term)
  verse = 'Unable to find Scripture' if verse.nil?
  { reference: term, verse: verse }
end

.read(file) ⇒ Object



49
50
51
52
# File 'lib/standard_works/file_helper.rb', line 49

def self.read(file)
  location = __dir__
  Oj.load_file("#{location}/source/#{file}.json", OPTIONS)
end

.referencesObject



29
30
31
32
# File 'lib/standard_works.rb', line 29

def self.references
  load_books if @references.nil?
  @references
end

.sections(power) ⇒ Object



19
20
21
22
23
# File 'lib/standard_works/file_helper.rb', line 19

def self.sections(power)
  power[:sections].each do |section|
    section[:verses].each { |verse| add_reference(verse) }
  end
end

.verse(term) ⇒ Object



18
19
20
# File 'lib/standard_works.rb', line 18

def self.verse(term)
  lookup(term)[:verse]
end