Class: Quote

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

Constant Summary collapse

@@all =
[]
@@dialouge_quotes =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, character = "") ⇒ Quote



11
12
13
14
15
16
17
18
19
# File 'lib/quote.rb', line 11

def initialize(content, character="")
    @content = content
    if character != ""
      self.character=(character)
    else
      @@dialouge_quotes << self
  end
  @@all << self
end

Instance Attribute Details

#characterObject

Returns the value of attribute character.



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

def character
  @character
end

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

Class Method Details

.allObject



30
31
32
# File 'lib/quote.rb', line 30

def self.all
  @@all
end

.find_character_by_name(name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/quote.rb', line 40

def self.find_character_by_name(name)
  character = nil
  self.all.each do |quote|
    if quote.character != nil
      if quote.character.name == name
        character = quote.character
      end
    end
  end
  character
end

.get_dialougeObject



52
53
54
55
56
# File 'lib/quote.rb', line 52

def self.get_dialouge
  n = @@dialouge_quotes.size - 1
  r = rand(0..n)
  puts "#{@@dialouge_quotes[r].content}"
end

.get_randomObject



58
59
60
61
62
63
64
65
66
# File 'lib/quote.rb', line 58

def self.get_random
  n = @@all.size - 1
  r = rand(0..n)
  if @@all[r].character != nil
    puts "#{@@all[r].content} -#{@@all[r].character.name}"
  else
    puts "#{@@all[r].content}"
  end
end

.list_all_quotesObject



34
35
36
37
38
# File 'lib/quote.rb', line 34

def self.list_all_quotes
  @@all.each do |quote|
    puts quote.content
  end  
end