Class: IntermatScrape::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/intermat_scrape/scraper.rb

Constant Summary collapse

BASE_URL =
'https://www.intermatwrestle.com/rankings/college/'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#weight_classObject

Returns the value of attribute weight_class.



2
3
4
# File 'lib/intermat_scrape/scraper.rb', line 2

def weight_class
  @weight_class
end

Class Method Details

.create_hash_from_row(row) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/intermat_scrape/scraper.rb', line 14

def self.create_hash_from_row(row)
  {
    rank: row.children[1].text,
    name: row.css(':nth-child(2) a').text,
    school: row.css(':nth-child(3)').text,
    class_standing: row.css(':nth-child(4)').text,
    conference: row.css(':nth-child(5)').text
  }
end

.create_wrestlers(weight_class) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/intermat_scrape/scraper.rb', line 24

def self.create_wrestlers(weight_class)
  get_rows(weight_class).collect do |row|
    wrestler_hash = create_hash_from_row(row)
    IntermatScrape::Wrestler.new(wrestler_hash).tap do |w|
      weight_class.add_wrestler(w)
    end
  end
end

.get_doc_by_weight(weight_class) ⇒ Object



6
7
8
# File 'lib/intermat_scrape/scraper.rb', line 6

def self.get_doc_by_weight(weight_class)
  Nokogiri::HTML(open(BASE_URL + weight_class.weight))
end

.get_rows(weight_class) ⇒ Object



10
11
12
# File 'lib/intermat_scrape/scraper.rb', line 10

def self.get_rows(weight_class)
  get_doc_by_weight(weight_class).css('table.table tbody tr')
end