Class: TildeScraper::Topic

Inherits:
Object
  • Object
show all
Extended by:
Memorable::ClassMethods
Includes:
Memorable::InstanceMethods
Defined in:
lib/tilde_scraper/topic/topic.rb

Direct Known Subclasses

LinkTopic, TextTopic

Defined Under Namespace

Classes: TopicError

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Memorable::ClassMethods

create, create_from_array

Methods included from Memorable::InstanceMethods

#add_attributes, #initialize

Instance Attribute Details

#ageObject

Returns the value of attribute age.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def age
  @age
end

#comment_countObject

Returns the value of attribute comment_count.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def comment_count
  @comment_count
end

Returns the value of attribute comment_link.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def comment_link
  @comment_link
end

#groupObject

Returns the value of attribute group.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def group
  @group
end

#page_idObject

Returns the value of attribute page_id.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def page_id
  @page_id
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def title
  @title
end

#votesObject

Returns the value of attribute votes.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def votes
  @votes
end

#word_countObject

Returns the value of attribute word_count.



2
3
4
# File 'lib/tilde_scraper/topic/topic.rb', line 2

def word_count
  @word_count
end

Class Method Details

.allObject



13
14
15
# File 'lib/tilde_scraper/topic/topic.rb', line 13

def self.all
  @@all
end

.create_from_array(array) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tilde_scraper/topic/topic.rb', line 17

def self.create_from_array(array)
  array.each do |attributes|
    if attributes.keys.include?(:topic_text)
      TildeScraper::TextTopic.create(attributes)
    elsif attributes.keys.include?(:link)
      TildeScraper::LinkTopic.create(attributes)
    else
      binding.pry
      raise TopicError
    end
  end
end

.find_by_page_id(id) ⇒ Object



9
10
11
# File 'lib/tilde_scraper/topic/topic.rb', line 9

def self.find_by_page_id(id)
  all.select { |topic| topic.page_id == id }
end

Instance Method Details

#commentsObject



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

def comments
  TildeScraper::Comment.find_by_url(comment_link)
end

#displayObject



34
35
36
37
# File 'lib/tilde_scraper/topic/topic.rb', line 34

def display
  puts "#{title} Votes:#{votes}"
  puts "#{group} WC:#{word_count} #{age} #{comment_count}"
end