dev/wip_excel_parsing #1
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
|||
doc/
|
||||
.yardoc/
|
||||
help
|
||||
temp/
|
||||
Neph marked this conversation as resolved
Outdated
|
2
Gemfile
2
Gemfile
|
@ -44,3 +44,5 @@ group :test do
|
|||
gem "mocha", "~> 1"
|
||||
# gem "simplecov", "~> 0.21.2", require: false
|
||||
end
|
||||
|
||||
gem "roo", "~> 2.9.0"
|
||||
|
|
|
@ -37,17 +37,24 @@ GEM
|
|||
minitest (5.16.3)
|
||||
mocha (1.14.0)
|
||||
netrc (0.11.0)
|
||||
nokogiri (1.13.8-x86_64-linux)
|
||||
racc (~> 1.4)
|
||||
opus-ruby (1.0.1)
|
||||
ffi
|
||||
pry (0.14.1)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
racc (1.6.0)
|
||||
rake (13.0.6)
|
||||
rest-client (2.1.0)
|
||||
http-accept (>= 1.7.0, < 2.0)
|
||||
http-cookie (>= 1.0.2, < 2.0)
|
||||
mime-types (>= 1.16, < 4.0)
|
||||
netrc (~> 0.8)
|
||||
roo (2.9.0)
|
||||
nokogiri (~> 1)
|
||||
rubyzip (>= 1.3.0, < 3.0.0)
|
||||
rubyzip (2.3.2)
|
||||
sequel (5.60.1)
|
||||
sqlite3 (1.5.0-x86_64-linux)
|
||||
tzinfo (2.0.5)
|
||||
|
@ -73,6 +80,7 @@ DEPENDENCIES
|
|||
mocha (~> 1)
|
||||
pry (~> 0)
|
||||
rake (~> 13)
|
||||
roo (~> 2.9.0)
|
||||
sequel (~> 5)
|
||||
sqlite3 (~> 1)
|
||||
|
||||
|
|
29
src/metal_adventures/character/import_neph_sheet.rb
Normal file
29
src/metal_adventures/character/import_neph_sheet.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'roo'
|
||||
|
||||
module MetalAdventures
|
||||
class Character
|
||||
module ImportNephSheet
|
||||
def self.import(path:)
|
||||
xls = Roo::Spreadsheet.open(path, extension: :xlsx)
|
||||
|
||||
new_character = Character.new(name: xls.sheet(0).b3).save
|
||||
|
||||
sheet_data = xls.sheet("DATA").to_a
|
||||
abi_index = sheet_data.find_index { |row| row[0] == "Agilité" }
|
||||
slice = sheet_data[abi_index..].map{ |abi| abi.each_slice(4).to_a }
|
||||
|
||||
abi = slice[0].map { |tuple| Ability.new(name: tuple[0], value: tuple[3], character: new_character).save }
|
||||
slice[2..].each do |line|
|
||||
line.each.with_index do |cell, column_id|
|
||||
if cell[0]
|
||||
Skill.new(name: cell[0], value: cell[3], ability: abi[column_id], character: new_character).save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
new_character
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user
temp/ should suffice