Class: Quote
- Inherits:
-
Object
- Object
- Quote
- Defined in:
- lib/quote.rb
Constant Summary collapse
- @@all =
[]
- @@dialouge_quotes =
[]
Instance Attribute Summary collapse
-
#character ⇒ Object
Returns the value of attribute character.
-
#content ⇒ Object
Returns the value of attribute content.
Class Method Summary collapse
- .all ⇒ Object
- .find_character_by_name(name) ⇒ Object
- .get_dialouge ⇒ Object
- .get_random ⇒ Object
- .list_all_quotes ⇒ Object
Instance Method Summary collapse
-
#initialize(content, character = "") ⇒ Quote
constructor
A new instance of Quote.
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
#character ⇒ Object
Returns the value of attribute character.
6 7 8 |
# File 'lib/quote.rb', line 6 def character @character end |
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/quote.rb', line 6 def content @content end |
Class Method Details
.all ⇒ Object
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_dialouge ⇒ Object
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_random ⇒ Object
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_quotes ⇒ Object
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 |