Class: PfrpgImport::HeroclassSpells

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(csv_rows) ⇒ HeroclassSpells

Returns a new instance of HeroclassSpells.



5
6
7
# File 'lib/pfrpg_import/heroclass_spells.rb', line 5

def initialize(csv_rows)
  @spells = pretty_print(parse_spells(csv_rows))
end

Instance Attribute Details

#spellsObject (readonly)

Returns the value of attribute spells.



4
5
6
# File 'lib/pfrpg_import/heroclass_spells.rb', line 4

def spells
  @spells
end

Instance Method Details

#parse_spells(rows) ⇒ Object



9
10
11
# File 'lib/pfrpg_import/heroclass_spells.rb', line 9

def parse_spells(rows)
  rows.map { |row| to_spell_row(row[6..15]) }
end

#pretty_print(rows) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/pfrpg_import/heroclass_spells.rb', line 23

def pretty_print(rows)
  str = "[\n"
  rows.each do |row|
    str += "\t\t\t\t#{row},\n"
  end
  str += "\t\t\t]\n"
  str
end

#to_spell_row(row) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/pfrpg_import/heroclass_spells.rb', line 13

def to_spell_row(row)
  spells = []
  for i in 0..9
    f = row[i] || "0"
    f = f.gsub("","0")
    spells[i] = Integer(f)
  end
  return spells
end