Sha256: 5af2375cadf8f08320da5b6e7c47e2d6d6102a9f117617475a3e60a333af0296

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

require 'pry'
require 'open-uri'
require 'nokogiri'

class Archivist
  
  attr_reader :ancestries, :backgrounds, :classes
  
  @@source = "https://2e.aonprd.com/"
  
  def page_finder(aspect)
    Nokogiri::HTML(open(@@source+aspect.to_s.capitalize+'.aspx'))
  end
  
  def hasher(aspect, header)
    dictionary = {}
    page_finder(aspect).css("#{header} a").each{ |role|
      if role.attribute("href").value.include?("#{aspect.to_s.capitalize}.aspx?ID")
        dictionary[role.text] = role.attribute("href").value
      end
    }
    dictionary
  end
  
  def initialize
    @ancestries = hasher(:ancestries, "h2")
    @backgrounds = hasher(:backgrounds, "h1")
    @classes = hasher(:classes, "h1")
  end
  
  def summarize(option, aspect) # => grabs flavor blurb
    page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option]
    blurb = Nokogiri::HTML(open(page))
    #binding.pry
    if page.include?("Backgrounds")
      puts blurb.text.match(/pg. 6\d(.+)Choose/)[1]
    else
      puts blurb.css("i")[1].text
    end
  end

  def confirm(option, aspect)
    return true if self.send("#{aspect}").include?(option)
    puts "Choose from the list of #{aspect} above."
  end  

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
p2e_builder-0.1.4 lib/Archivist.rb
p2e_builder-0.1.3 lib/Archivist.rb
p2e_builder-0.1.2 lib/Archivist.rb
p2e_builder-0.1.1 lib/Archivist.rb
p2e_builder-0.1.0 lib/Archivist.rb