Class: PfrpgImport::HeroclassSpells
- Inherits:
-
Object
- Object
- PfrpgImport::HeroclassSpells
- Defined in:
- lib/pfrpg_import/heroclass_spells.rb
Instance Attribute Summary collapse
-
#spells ⇒ Object
readonly
Returns the value of attribute spells.
Instance Method Summary collapse
-
#initialize(csv_rows) ⇒ HeroclassSpells
constructor
A new instance of HeroclassSpells.
- #parse_spells(rows) ⇒ Object
- #pretty_print(rows) ⇒ Object
- #to_spell_row(row) ⇒ Object
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
#spells ⇒ Object (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 |