Class: Crags::Category

Inherits:
Object
  • Object
show all
Extended by:
Fetcher
Defined in:
lib/crags/category.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fetcher

fetch_doc, fetch_html, fetch_request

Constructor Details

#initialize(name, abbr) ⇒ Category

Returns a new instance of Category.



6
7
8
9
# File 'lib/crags/category.rb', line 6

def initialize(name, abbr)
  @name = name
  @url = "/#{abbr}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/crags/category.rb', line 4

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/crags/category.rb', line 4

def url
  @url
end

Class Method Details

.allObject



21
22
23
24
25
26
27
# File 'lib/crags/category.rb', line 21

def self.all
  links.collect do |link|
    url = link["href"]
    name = link.inner_html
    Category.new(name, url)
  end
end

.docObject



11
12
13
# File 'lib/crags/category.rb', line 11

def self.doc
  fetch_doc(Config.category_url)
end


15
16
17
18
19
# File 'lib/crags/category.rb', line 15

def self.links
  doc.search("div.col a").select do |link|
    (link["href"] =~ /forum/).nil?
  end
end