Class: Hedbergism::QuoteFile

Inherits:
Object
  • Object
show all
Defined in:
lib/hedbergism/quote_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ QuoteFile

Returns a new instance of QuoteFile.



6
7
8
9
10
11
# File 'lib/hedbergism/quote_file.rb', line 6

def initialize(file_name)
  @lines = []
  File.readlines(file_name).each do |line|
    addQuote(line)
  end
end

Instance Method Details

#addQuote(line) ⇒ Object



13
14
15
# File 'lib/hedbergism/quote_file.rb', line 13

def addQuote(line)
  @lines.push(Quote.new(line))
end

#firstlineObject



17
18
19
# File 'lib/hedbergism/quote_file.rb', line 17

def firstline
  @lines[0].to_s
end

#randomObject



21
22
23
# File 'lib/hedbergism/quote_file.rb', line 21

def random
  @lines.sample.to_s
end