class RawReader

Constants

STATE_TRANSITION

Attributes

advanced_cat[R]
concentration_cat[R]
profession_advanced[R]
profession_concentration_group[R]
profession_concentration_hierarchy[R]
profession_concentrations[R]
profession_extension[R]
professions[R]
skill_cat[R]
skill_countered[R]
skill_counters[R]
skill_group[R]
skill_list[R]
skill_mp_cost[R]
strain_restrictions[R]
strain_specs[R]
strain_stats[R]
strains[R]

Public Class Methods

new(filepath: f = nil) click to toggle source
# File lib/RawReader.rb, line 34
def initialize filepath:
  f = nil
  @skill_list = Hash.new
  @skill_cat = Hash.new
  @advanced_cat = Hash.new
  @concentration_cat = Hash.new
  @strains = Set.new
  @strain_restrictions = Hash.new
  @skill_group = Hash.new
  @skill_counters = Hash.new
  @skill_countered = Hash.new
  @strain_specs = Hash.new
  @strain_stats = Hash.new
  @professions = Set.new
  @profession_concentrations = Hash.new
  @profession_advanced = Hash.new
  @profession_concentration_hierarchy = Hash.new
  @profession_concentration_group = Hash.new
  @profession_extension = Hash.new
  @skill_mp_cost = Hash.new

  @mutiline_state = nil

  begin
    f = File.read(filepath)
  rescue Errno::ENOENT => e
    puts "File not found: #{filepath}"
    puts e.backtrace
    exit 1
  end

  split_by_sections(raw: f)
  post_process_sets

  #ap @skill_cat
  #ap @advanced_cat
  #ap @profession_concentrations
  #ap @concentration_cat
  # ap @skill_counters
  # ap @skill_countered
  # ap @profession_concentration_group
  # ap @skill_list
  # ap @skill_mp_cost
end

Private Instance Methods

detect_state_transition(current_state:, current_profession:, line: profession = nil) click to toggle source
# File lib/RawReader.rb, line 98
def detect_state_transition current_state:, current_profession:, line:
  profession = nil
  transition = STATE_TRANSITION[current_state]
  if transition[:pattern] =~ line
    if transition[:next] == :profession
      profession = extract_profession_name(line: line) || current_profession
    end
    return transition[:next], profession
  elsif current_state == :profession || current_state == :adv_skills
    profession = extract_profession_name(line: line) || current_profession
  end

  return current_state, profession
end
extract_profession_name(line: if line =~ /== ([\w\s\-]+) ==/) click to toggle source
# File lib/RawReader.rb, line 113
def extract_profession_name line:
  if line =~ /== ([\w\s\-]+) ==/
    return $1.strip.to_sym
  end
post_process_sets() click to toggle source
# File lib/RawReader.rb, line 80
def post_process_sets
  @skill_cat.each do |_junk, data|
    data[:innate] = data[:innate].to_a
    data[:innate_disadvantage] = data[:innate_disadvantage].to_a
    data[:innate_disabled] = data[:innate_disabled].to_a
  end
end
split_by_sections(raw: state = :undef) click to toggle source
# File lib/RawReader.rb, line 88
def split_by_sections raw:
  state = :undef
  profession = :undef

  raw.split(/[\r\n]+/).each do |line|
    state, profession = detect_state_transition(current_state: state, current_profession: profession, line: line)
    execute_state_task state: state, profession: profession, line: line
  end
end