Class: PathfinderDeckBuilder::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Compiler

Returns a new instance of Compiler.



22
23
24
# File 'lib/compiler.rb', line 22

def initialize(file_path)
  @file_path = file_path
end

Instance Attribute Details

#deckObject

Returns the value of attribute deck.



19
20
21
# File 'lib/compiler.rb', line 19

def deck
  @deck
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



20
21
22
# File 'lib/compiler.rb', line 20

def file_path
  @file_path
end

#myXMLObject (readonly)

Returns the value of attribute myXML.



20
21
22
# File 'lib/compiler.rb', line 20

def myXML
  @myXML
end

#setup_cardsObject (readonly)

Returns the value of attribute setup_cards.



20
21
22
# File 'lib/compiler.rb', line 20

def setup_cards
  @setup_cards
end

Instance Method Details

#build_cards(index = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
# 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

#compileObject



74
75
76
77
78
79
80
# File 'lib/compiler.rb', line 74

def compile
  if is_party?
    compile_party
  else
    compile_individual
  end
end

#compile_individualObject



30
31
32
33
34
35
36
# File 'lib/compiler.rb', line 30

def compile_individual
  read_file_path

  build_cards

  save_deck("#{@deck.cards.first[:title]}"+".json")
end

#compile_partyObject



38
39
40
41
42
43
44
45
46
# 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?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/compiler.rb', line 26

def is_party?
  Crack::XML.parse(File.read(@file_path))["document"]["public"]["character"].class == Array
end

#prepare_for_s3Object



48
49
50
51
52
53
54
# 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) ⇒ Object



101
102
103
# File 'lib/compiler.rb', line 101

def prepare_json_for_s3(xml)
  @myXML = Crack::XML.parse(xml)
end

#read_file_pathObject



97
98
99
# File 'lib/compiler.rb', line 97

def read_file_path
  @myXML = Crack::XML.parse(File.read(@file_path))
end

#save_deck(file_name) ⇒ Object



82
83
84
85
# 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

#setupObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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