class CorpusGenerator::Poet

Attributes

name[RW]
poems[RW]
profile_url[RW]

Public Class Methods

all() click to toggle source

Class Methods

# File lib/random_poetry_scraper/poet.rb, line 22
def self.all
    @@all
end
find_by_name(name) click to toggle source
# File lib/random_poetry_scraper/poet.rb, line 26
def self.find_by_name(name)
    self.all.detect {|poet| poet.name == name}
end
find_or_create(attributes) click to toggle source
# File lib/random_poetry_scraper/poet.rb, line 31
def self.find_or_create(attributes)
    # TODO assumes that there will be a name attribute in hash
    # ...assumes that a hash will be passed in
    if poet = self.find_by_name(attributes[:name])
        return poet
    else
        self.new(attributes)
    end
end
new(attributes_hash) click to toggle source
# File lib/random_poetry_scraper/poet.rb, line 6
def initialize(attributes_hash)

    self.poems = []

    attributes_hash.each do |attribute, value|
        self.send("#{attribute}=", value)
    end
    self.class.all << self
end

Public Instance Methods

add_poem(poem) click to toggle source
# File lib/random_poetry_scraper/poet.rb, line 16
def add_poem(poem)
    self.poems << poem unless self.poems.detect {|poem| poem == self}
end