Class: FortunesApp

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/fortunes.rb

Defined Under Namespace

Classes: Fortune

Instance Method Summary collapse

Instance Method Details

#extract_sampleObject



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

def extract_sample
  -> (file_content) {Fortune.new(file_content.sample[0]).message}
end

#generate_jsonObject



33
34
35
# File 'lib/fortunes.rb', line 33

def generate_json
  -> (message) {JSON.generate({:message=> message})}
end

#read_file(file_name) ⇒ Object



24
25
26
27
# File 'lib/fortunes.rb', line 24

def read_file(file_name)
  fortune_path = File.join( File.dirname(__FILE__), "fortunes/#{file_name}" )
  File.open(fortune_path).read.scan(/((?<=%).+?(?=%))/m)
end