class Gust::Spreadsheet::Loader
Attributes
object_groups[R]
objects[R]
workbook_filepath[R]
Public Class Methods
load(workbook_filepath)
click to toggle source
# File lib/rb-gust/spreadsheet/loader.rb, line 49 def self.load workbook_filepath loader = self.new(workbook_filepath) loader.script end
new(workbook_filepath)
click to toggle source
# File lib/rb-gust/spreadsheet/loader.rb, line 6 def initialize workbook_filepath @workbook_filepath = workbook_filepath @_workbook = ::Spreadsheet.open(workbook_filepath) @object_groups = {} end
Public Instance Methods
build_object_groups()
click to toggle source
# File lib/rb-gust/spreadsheet/loader.rb, line 13 def build_object_groups @titles.each_with_index do |title,i| group_name = ActiveSupport::Inflector.tableize(title).to_sym @object_groups[group_name] = group_objects(@headers[i], @objects[i]) end end
group_objects(headers, object_data)
click to toggle source
# File lib/rb-gust/spreadsheet/loader.rb, line 20 def group_objects headers, object_data group = [] object_data.each do |object_attributes| next if object_attributes.compact.empty? group << hashify_object(headers, object_attributes) end group end
hashify_object(headers, object_attributes)
click to toggle source
# File lib/rb-gust/spreadsheet/loader.rb, line 29 def hashify_object(headers, object_attributes) hash = {} headers.each_with_index do |header, i| hash[header.to_sym] = object_attributes[i] end hash end
script()
click to toggle source
# File lib/rb-gust/spreadsheet/loader.rb, line 37 def script _workbook.worksheets.each do |_ws| @ws = Gust::Spreadsheet::Worksheet.new(_ws) @titles = @ws.titles @headers = @ws.headers @objects = @ws.objects build_object_groups end @object_groups end
Private Instance Methods
_workbook()
click to toggle source
Hide any references to ::Spreadsheet objects
# File lib/rb-gust/spreadsheet/loader.rb, line 57 def _workbook @_workbook end