class Shoji::Excel
Constants
- READER
Public Class Methods
convert_to_hash(filename, opts = {})
click to toggle source
# File lib/shoji/excel.rb, line 28 def self.convert_to_hash(filename, opts = {}) opts_for_parse = opts.slice(:sheet_index) opts_for_convert = opts.slice(:header) rows = self.rows(filename, opts) return {} if rows.size < 2 list = [] header = rows.shift header = opts_for_convert[:header] if opts_for_convert[:header] rows.each do |row| list << make_hash(header, row) end list end
foreach(filename, opts = {}, &block)
click to toggle source
# File lib/shoji/excel.rb, line 12 def self.foreach(filename, opts = {}, &block) raise 'Block must be exist.' unless block_given? READER.new(filename).foreach(opts, &block) end
new(filename)
click to toggle source
# File lib/shoji/excel.rb, line 42 def initialize(filename) @filename = filename end
row_size(filename, opts = {})
click to toggle source
# File lib/shoji/excel.rb, line 24 def self.row_size(filename, opts = {}) READER.new(filename).row_size(opts) end
rows(filename, opts = {})
click to toggle source
# File lib/shoji/excel.rb, line 20 def self.rows(filename, opts = {}) READER.new(filename).rows(opts) end
valid_file?(filename)
click to toggle source
# File lib/shoji/excel.rb, line 16 def self.valid_file?(filename) READER.valid_file? filename end
Private Class Methods
make_hash(header_columns, row_columns)
click to toggle source
# File lib/shoji/excel.rb, line 69 def self.make_hash(header_columns, row_columns) h = {} header_columns.size.times do |i| h[header_columns[i]] = row_columns[i] end h end
process_rows(sheet, &block)
click to toggle source
# File lib/shoji/excel.rb, line 63 def self.process_rows(sheet, &block) sheet.each do |row| cells = cells_from_row(row) block.call(cells) end end
Public Instance Methods
convert_to_hash(opts = {})
click to toggle source
# File lib/shoji/excel.rb, line 58 def convert_to_hash(opts = {}) self.class.convert_to_hash(@filename, opts) end
foreach(opts = {}, &block)
click to toggle source
# File lib/shoji/excel.rb, line 46 def foreach(opts = {}, &block) self.class.foreach(@filename, opts, &block) end
row_size(opts = {})
click to toggle source
# File lib/shoji/excel.rb, line 55 def row_size(opts = {}) self.class.row_size(@filename, opts) end
rows(opts = {})
click to toggle source
# File lib/shoji/excel.rb, line 52 def rows(opts = {}) self.class.rows(@filename, opts) end
valid_file?()
click to toggle source
# File lib/shoji/excel.rb, line 49 def valid_file? self.class.valid_file? @filename end