class Archivist

Attributes

ancestries[R]
backgrounds[R]
classes[R]

Public Class Methods

new() click to toggle source
# File lib/Archivist.rb, line 30
def initialize
  @ancestries = hasher(:ancestries, "h2")
  @backgrounds = hasher(:backgrounds, "h1")
  @classes = hasher(:classes, "h1")
end

Public Instance Methods

ance_stats(option, aspect) click to toggle source
# File lib/Archivist.rb, line 46
def ance_stats(option, aspect) # => grabs stats from ancestry
  page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option]
  blurb = Nokogiri::HTML(open(page))
  blurb.text.match(@@ance_parser)
end
back_stats(option, aspect) click to toggle source
# File lib/Archivist.rb, line 52
def back_stats(option, aspect) # => grabs stats from background
  page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option]
  blurb = Nokogiri::HTML(open(page))
  blurb.text.match(@@back_parser)
end
clas_stats(option, aspect) click to toggle source
# File lib/Archivist.rb, line 58
def clas_stats(option, aspect) # => grabs stats from class
  page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option]
  blurb = Nokogiri::HTML(open(page))
  blurb.css("b")[2].text.match(@@clas_parser)
end
confirm(option, aspect) click to toggle source
# File lib/Archivist.rb, line 64
def confirm(option, aspect)
  return true if self.send("#{aspect}").include?(option)
  puts "Choose from the list of #{aspect} above."
end
hasher(aspect, header) click to toggle source
# File lib/Archivist.rb, line 20
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
page_finder(aspect) click to toggle source
# File lib/Archivist.rb, line 16
def page_finder(aspect)
  Nokogiri::HTML(open(@@source+aspect.to_s.capitalize+'.aspx'))
end
summarize(option, aspect) click to toggle source
# File lib/Archivist.rb, line 36
def summarize(option, aspect) # => grabs flavor blurb
  page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option]
  blurb = Nokogiri::HTML(open(page))
  if page.include?("Backgrounds")
    puts blurb.text.match(/pg. 6\d(.+)Choose/)[1]
  else
    puts blurb.css("i")[1].text
  end
end