Module: Bereshit

Defined in:
lib/bereshit.rb,
lib/bereshit/version.rb

Defined Under Namespace

Classes: Loader

Constant Summary collapse

PUNCTUATION =
['.', ',', '!', '?', ':']
LOCALE =
['hebrew', 'english', 'kreyol']
VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.p(count = 5, plainText = false, exclude_trailing_period = false, locale = "english") ⇒ Object



56
57
58
# File 'lib/bereshit.rb', line 56

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") ⇒ Object

Return Paragraphs



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
# File 'lib/bereshit.rb', line 25

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') ⇒ Object

Return a sermon



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bereshit.rb', line 12

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