Method: Scraper#pull_attrs

Defined in:
lib/Theatre_Explorer/scraper.rb

#pull_attrsObject



23
24
25
26
27
28
29
30
31
32
33
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
# File 'lib/Theatre_Explorer/scraper.rb', line 23

def pull_attrs
    attributes = {}
    attributes["show"] = @page.at("h2").text.gsub(" Show Information","")
    attributes["year"] = @page.at("tr:nth-child(1) td+ td span").text.match(/\d{4}/).to_s
    attributes["label"] = "#{attributes["show"]} - #{attributes["year"]}"
    attributes["details"] = {}
    prod_information = @page.search(".production-table span")
        prod_information.each.with_index do |e,i|
            case e.text.strip
            when "Previews:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Opening:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Closing:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Theatres:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Production Type:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Run Type:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Market:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Running Time:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Intermissions:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Version:"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Official Website"
                attributes["details"][e.text] = prod_information[i + 1].text
            when "Show type"
                attributes["details"][e.text] = prod_information[i + 1].text
            end 
        end
    summary = @page.link_with(:href => /\d*.html/).click.at("style+ .col-12").text[/; (\w.*\.)\w/]
    attributes["details"]["summary"] = /; (\w.*\.)\w/.match(summary)[1].strip if summary
    attributes
end