Sha256: 354b4c25e0612acd3a4725d390eecd8f2e3976d3e22ddad503fb7bd24b5d241e

Contents?: true

Size: 1.22 KB

Versions: 18

Compression:

Stored size: 1.22 KB

Contents

require 'open-uri'
require 'nokogiri'
require 'pry'

class Quote
	attr_accessor :character, :content

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

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

    def character=(character)
    	if self.class.find_character_by_name(character) != nil
    		@character = self.class.find_character_by_name(character)
    	else	
    		@character = Character.new(character)
    	end
    	@character.add_quote(self)
 	end

	def self.all
		@@all
	end

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

	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

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

	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

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
the-office-quote-generator-0.1.8 lib/quote.rb
the-office-quote-generator-0.1.7 lib/quote.rb
the-office-quote-generator-0.1.6 lib/quote.rb
the-office-quote-generator-0.1.5 lib/quote.rb
the-office-quote-generator-0.1.4 lib/quote.rb
the-office-quote-generator-0.1.3 lib/quote.rb
the-office-quote-generator-0.1.2 lib/quote.rb
the-office-quote-generator-0.1.1 lib/quote.rb
the-office-quote-generator-0.1.0 lib/quote.rb
the-office-quote-generator-0.0.9 lib/quote.rb
the-office-quote-generator-0.0.8 lib/quote.rb
the-office-quote-generator-0.0.7 lib/quote.rb
the-office-quote-generator-0.0.6 lib/quote.rb
the-office-quote-generator-0.0.5 lib/quote.rb
the-office-quote-generator-0.0.4 lib/quote.rb
the-office-quote-generator-0.0.3 lib/quote.rb
the-office-quote-generator-0.0.2 lib/quote.rb
the-office-quote-generator-0.0.1 lib/quote.rb