-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bibles class with King James subclass (#1696)
Co-authored-by: Jac Bergenson <jac.bergenson@phishme.com>
- Loading branch information
1 parent
e9247c8
commit 800855f
Showing
5 changed files
with
31,280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Faker::Bibles::KingJames | ||
|
||
```ruby | ||
# List of b | ||
Faker::Bibles::KingJames::BOOKS #=> ["genesis", "exodus", "leviticus", "numbers", "deuteronomy", "joshua", "judges", "ruth", "one_samuel", "two_samuel", "one_kings", "two_kings", "one_chronicles", "two_chronicles", "ezra", "nehemiah", "esther", "job", "psalms", "proverbs", "ecclesiastes", "song_of_solomon", "isaiah", "jeremiah", "lamentations", "ezekiel", "daniel", "hosea", "joel", "amos", "obadiah", "jonah", "micah", "nahum", "habakkuk", "zephaniah", "haggai", "zechariah", "malachi", "matthew", "mark", "luke", "john", "acts", "romans", "one_corinthians", "two_corinthians", "galatians", "ephesians", "philippians", "colossians", "one_thessalonians", "two_thessalonians", "one_timothy", "two_timothy", "titus", "philemon", "hebrews", "james", "one_peter", "two_peter", "one_john", "two_john", "three_john", "jude", "revelation"] | ||
|
||
# Random book name (generated from BOOKS) | ||
Faker::Bibles::KingJames.book #=> "two_thessalonians" | ||
|
||
# Random verse. Takes three optional arguments: | ||
# prefix (bool): include/exclude prefix (default: true) | ||
# emphasis (bool): include/exclude markdown-compatible emphasis (italicized in original publication) (default: false) | ||
# books (string/array): which book(s) to use to select verse. (default: BOOKS) | ||
Faker::Bibles::KingJames.verse #=> "Jude 1:1 Jude, the servant of Jesus Christ, and brother of James, to them that are sanctified by God the Father, and preserved in Jesus Christ, and called:" | ||
|
||
|
||
# Random verse from a given book | ||
Faker::Bibles::KingJames.verse(books: 'genesis') #=> "Genesis 5:6 And Seth lived an hundred and five years, and begat Enos:" | ||
|
||
# Alias for random verse from a given book (replace verse with book name). Also takes prefix or emphasis args as shown above | ||
Faker::Bibles::KingJames.genesis #=> "Genesis 13:17 Arise, walk through the land in the length of it and in the breadth of it; for I will give it unto thee." | ||
|
||
# Random verse from array of books | ||
Faker::Bibles::KingJames.verse(books: %w[genesis exodus]) #=> "Exodus 34:2 And be ready in the morning, and come up in the morning unto mount Sinai, and present thyself there to me in the top of the mount." | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faker | ||
class Bibles | ||
class KingJames < Base | ||
BOOKS = %w[genesis exodus leviticus numbers deuteronomy joshua judges ruth one_samuel two_samuel one_kings two_kings one_chronicles two_chronicles ezra nehemiah esther job psalms proverbs ecclesiastes song_of_solomon isaiah jeremiah lamentations ezekiel daniel hosea joel amos obadiah jonah micah nahum habakkuk zephaniah haggai zechariah malachi matthew mark luke john acts romans one_corinthians two_corinthians galatians ephesians philippians colossians one_thessalonians two_thessalonians one_timothy two_timothy titus philemon hebrews james one_peter two_peter one_john two_john three_john jude revelation].freeze | ||
PREFIX_PATTERN = /^[[:alnum:] ]+?\d+?:\d+? / | ||
flexible :king_james | ||
|
||
class << self | ||
def book | ||
BOOKS.sample | ||
end | ||
|
||
def verse(prefix: true, emphasis: false, books: BOOKS) | ||
books = [books] unless books.is_a? Array | ||
validate_book_names(books) | ||
format(fetch("king_james.#{books.sample}"), prefix, emphasis) | ||
end | ||
|
||
BOOKS.each do |book| | ||
define_method(:"#{book}") do |prefix: true, emphasis: false| | ||
verse(prefix: prefix, emphasis: emphasis, books: book) | ||
end | ||
end | ||
|
||
private | ||
|
||
def invalid_book_names?(arr) | ||
(arr & BOOKS).size < arr.size | ||
end | ||
|
||
def validate_book_names(arr) | ||
raise ArgumentError, "Given book names: #{arr.join(', ')}. Valid: #{BOOKS.join(', ')}" if invalid_book_names?(arr) | ||
end | ||
|
||
def format(string, prefix, emphasis) | ||
string.gsub!(PREFIX_PATTERN, '') unless prefix | ||
string.delete!('*') unless emphasis | ||
string | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.