Class: Yodaism::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/yodaism/config.rb

Constant Summary collapse

FILE =
"#{file_path}/quotes/quotes.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
# File 'lib/yodaism/config.rb', line 8

def initialize
  @quotes = {}
  File.exists?(file) ? load_quotes_from_file : file_not_found
end

Instance Attribute Details

#quotesObject (readonly)

Returns the value of attribute quotes.



6
7
8
# File 'lib/yodaism/config.rb', line 6

def quotes
  @quotes
end

Instance Method Details

#fileObject



25
26
27
# File 'lib/yodaism/config.rb', line 25

def file
  FILE
end

#file_not_foundObject



13
14
15
16
# File 'lib/yodaism/config.rb', line 13

def file_not_found
  puts "could not find file in path #{FILE}"
  exit(1)
end

#load_quotes_from_fileObject



18
19
20
21
22
23
# File 'lib/yodaism/config.rb', line 18

def load_quotes_from_file
  f = File.new(file)
  f.each { |line| 
    @quotes[f.lineno-1] = line 
  }
end