Class: StarWarsComics::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/star-wars-comics/scraper.rb

Class Method Summary collapse

Class Method Details

.scrape_issue_info(issue) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/star-wars-comics/scraper.rb', line 34

def self.scrape_issue_info(issue)
  issue_info =  Nokogiri::HTML(open(BASE_PATH + issue.path)).css(
                "aside.portable-infobox")

  issue.name = issue_info.css("h2.pi-title").text

  attributions = issue_info.css("section.pi-item.pi-group div.pi-item")

  attributions.each do |attrib|
    attrib_type = attrib.css("h3.pi-data-label").text
    attrib_value = attrib.css("div.pi-data-value").text.sub(/\[.*\]/, "")

    unless attrib.css("div.pi-data-value a").empty?
      attrib_link = attrib.css("div.pi-data-value a").attribute("href").value
    end

    if attrib_type == "Writer"
      issue.writer =  StarWarsComics::Artists::Writer.find_or_create_by_name(
                      attrib_value, attrib_link)
    elsif attrib_type == "Penciller"
      issue.penciller = StarWarsComics::Artists::Penciller.find_or_create_by_name(
                        attrib_value, attrib_link)
    elsif attrib_type == "Letterer"
      issue.letterer =  StarWarsComics::Artists::Letterer.find_or_create_by_name(
                        attrib_value, attrib_link)
    elsif attrib_type == "Colorist"
      issue.colorist =  StarWarsComics::Artists::Colorist.find_or_create_by_name(
                        attrib_value, attrib_link)

    elsif attrib_type == "Publication date"
      issue.pub_date = attrib_value
    elsif attrib_type == "Pages"
      issue.pages = attrib_value
    end

  end
end

.scrape_issues(series) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/star-wars-comics/scraper.rb', line 21

def self.scrape_issues(series)
  issues =  Nokogiri::HTML(open(BASE_PATH + series.path)).css('td[style*="background-color:"] + td i a')

  last_issue = nil
  issues.each do |issue_link|
    issue = StarWarsComics::Issue.find_or_create_by_name(issue_link["title"], issue_link["href"])
    issue.series = series
    issue.last_issue = last_issue
    issue.last_issue.next_issue = issue unless last_issue == nil
    last_issue = issue
  end
end

.scrape_series(path, all_series) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/star-wars-comics/scraper.rb', line 3

def self.scrape_series(path, all_series)
  categories = Nokogiri::HTML(open(BASE_PATH + path)).css("div.CategoryTreeItem a")

  categories.each do |category|
    self.scrape_series(category["href"], all_series) unless self.dont_include(category)
  end

  series_link = Nokogiri::HTML(open(BASE_PATH + path)).css("div#mw-pages div a").first

  unless series_link == nil
    series = StarWarsComics::Series.new(series_link.text, series_link["href"])
    series.desc = Nokogiri::HTML(open(BASE_PATH + series.path)).css("div#mw-content-text p").first.text.sub(/\[.*\]/, "")
    all_series << series
  end

  all_series
end