This repository has been archived on 2021-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
d20pfsrd/lib/pf/class.rb

44 lines
1.2 KiB
Ruby

require "active_support"
require_relative "../page.rb"
module PF
class Class < Page
def get_info(start_with)
@main.find { |par| par.star_with?(start_with) }
end
# REJECT_INFOS = [:table, :section_15]
INFOS = {
role: lambda { |text| text },
alignment: lambda { |text| text },
hit_die: lambda { |text| text[1..-1].to_i },
starting_wealth: lambda { |text| text },
skill_ranks_per_level: lambda { |text| text[0].to_i },
}
def get_all_infos
@main
.filter { |child| child.match?(/^([\w ]+):/) }
.map { |info| info.split(":", 2) }
.map { |tuple| [tuple[0].strip.downcase.gsub(" ", "_").to_sym, tuple[1].strip] }
.to_h
.keep_if { |k, v| INFOS.key?(k) }
.map { |k, v| [k, INFOS[k].call(v)] }
.to_h
end
def to_ruby
parsed = parse
@main = parsed.css("div.article-content").children.map { |child| child.text.strip }.keep_if(&:present?)
@main.shift # drop the toc
@main.shift if @main.first.start_with?("Image") # drop the image
{
name: parsed.xpath("//h1").text,
description: @main.first,
**get_all_infos,
}
end
end
end