class PathfinderDeckBuilder::Compiler

Attributes

deck[RW]
file_path[R]
myXML[R]
setup_cards[R]

Public Class Methods

new(file_path) click to toggle source
# File lib/compiler.rb, line 22
def initialize(file_path)
  @file_path = file_path
end

Public Instance Methods

build_cards(index=nil) click to toggle source
# File lib/compiler.rb, line 87
def build_cards(index=nil)
  setup

  @setup_cards.each { |card| card.create_card(index) }

  @setup_cards.each do |card|
    card.class_cards.each {|class_card| @deck.cards << class_card}
  end
end
compile() click to toggle source
# File lib/compiler.rb, line 74
def compile
  if is_party?
    compile_party
  else
    compile_individual
  end
end
compile_individual() click to toggle source
# File lib/compiler.rb, line 30
def compile_individual
  read_file_path

  build_cards

  save_deck("#{@deck.cards.first[:title]}"+".json")
end
compile_party() click to toggle source
# File lib/compiler.rb, line 38
def compile_party
  read_file_path
  @myXML["document"]["public"]["character"].each_with_index do |character, index|

    build_cards(index)

    save_deck("#{character["name"]}"+".json")
  end
end
is_party?() click to toggle source
# File lib/compiler.rb, line 26
def is_party?
  Crack::XML.parse(File.read(@file_path))["document"]["public"]["character"].class == Array
end
prepare_for_s3() click to toggle source
# File lib/compiler.rb, line 48
def prepare_for_s3
  prepare_json_for_s3(@file_path)
  
  build_cards

  return @deck.cards
end
prepare_json_for_s3(xml) click to toggle source
# File lib/compiler.rb, line 101
def prepare_json_for_s3(xml)
  @myXML = Crack::XML.parse(xml)
end
read_file_path() click to toggle source
# File lib/compiler.rb, line 97
def read_file_path
  @myXML = Crack::XML.parse(File.read(@file_path))
end
save_deck(file_name) click to toggle source
# File lib/compiler.rb, line 82
def save_deck(file_name)
  @deck.save_deck(file_name)
  puts "Please check your current directory for a JSON file with your deck name."
end
setup() click to toggle source
# File lib/compiler.rb, line 56
def setup
  @deck = PathfinderDeckBuilder::Deck.new
  @setup_cards = [
    @character = PathfinderDeckBuilder::CharacterCard.new(@myXML),
    @melee_weapons = PathfinderDeckBuilder::MeleeWeaponCard.new(@myXML),
    @ranged_weapons = PathfinderDeckBuilder::RangedWeaponCard.new(@myXML),
    @armors = PathfinderDeckBuilder::ArmorCard.new(@myXML),
    @tracked_resources = PathfinderDeckBuilder::TrackedResourceCard.new(@myXML),
    @spells = PathfinderDeckBuilder::SpellCard.new(@myXML),
    @skills = PathfinderDeckBuilder::SkillCard.new(@myXML),
    @defenses = PathfinderDeckBuilder::DefensiveAbilityCard.new(@myXML),
    @feats = PathfinderDeckBuilder::FeatCard.new(@myXML),
    @traits = PathfinderDeckBuilder::TraitCard.new(@myXML),
    @special_abilities = PathfinderDeckBuilder::SpecialAbilityCard.new(@myXML),
    @special_attacks = PathfinderDeckBuilder::SpecialAttackCard.new(@myXML)
  ]
end