module Bereshit

Constants

LOCALE
PUNCTUATION
VERSION

Public Class Methods

p(count = 5, plainText = false, exclude_trailing_period = false, locale="english") click to toggle source
# File lib/bereshit.rb, line 55
def self.p(count = 5, plainText = false, exclude_trailing_period = false, locale="english")
  self.paragraphs(count, plainText, exclude_trailing_period, locale)
end
paragraphs(count = 5, plainText = false, exclude_trailing_period = false, locale="english") click to toggle source

Return Paragraphs

# File lib/bereshit.rb, line 24
def self.paragraphs(count = 5, plainText = false, exclude_trailing_period = false, locale="english")

  #if you have a typo in the locale name THAN thre program will fallback to english
  locale = LOCALE.include?(locale) ? locale : 'english'

  #load the json file 'locale/english/bereshit.json'
  loader = Loader.new('locale/' + locale +'/bereshit.json')

  # Start at a random index in the array
  start_inx = rand(loader.lines.count - count)

  # Check for overrun
  raise "I can't retrieve that many paragraphs. Try a smaller value." if (start_inx + count) > loader.lines.count

  # Build paragraphs from array
  paragraphs = loader.lines[start_inx, count]

  # Build final format based on parameters
  paragraphs.map! do |line|

    remove_puctuation(line) if exclude_trailing_period
    if plainText
      line = "#{line}"
    else
      line = "<p>#{line}</p>"
    end
  end

  paragraphs.join('')
end
sermon(locale='english') click to toggle source

Return a sermon

# File lib/bereshit.rb, line 11
def self.sermon(locale='english')
  #sermons scrappe from http://www.sermonnotebook.org/otsermons.htm

  #if you have a typo in the locale name THAN thre program will fallback to english
  locale = LOCALE.include?(locale) ? locale : 'english'

  #load the json file 'locale/english/sermon.json'
  loader = Loader.new('locale/' + locale +'/sermon.json')

    return loader.lines.sample
end

Private Class Methods

remove_puctuation(line) click to toggle source
# File lib/bereshit.rb, line 62
def self.remove_puctuation(line)
  PUNCTUATION.each do |punct|
    if line[line.length - 1].to_s == punct
      line[line.length - 1] = ""
      return
    end
  end
end