Class: CorpusGenerator::Poet

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes_hash) ⇒ Poet

Returns a new instance of Poet.



6
7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/random_poetry_scraper/poet.rb', line 2

def name
  @name
end

#poemsObject

Returns the value of attribute poems.



2
3
4
# File 'lib/random_poetry_scraper/poet.rb', line 2

def poems
  @poems
end

#profile_urlObject

Returns the value of attribute profile_url.



2
3
4
# File 'lib/random_poetry_scraper/poet.rb', line 2

def profile_url
  @profile_url
end

Class Method Details

.allObject

Class Methods



22
23
24
# File 'lib/random_poetry_scraper/poet.rb', line 22

def self.all
    @@all
end

.find_by_name(name) ⇒ Object



26
27
28
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
# 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

Instance Method Details

#add_poem(poem) ⇒ Object



16
17
18
# File 'lib/random_poetry_scraper/poet.rb', line 16

def add_poem(poem)
    self.poems << poem unless self.poems.detect {|poem| poem == self}
end