Class: Shoji::Excel
Defined Under Namespace
Classes: Reader
Constant Summary
collapse
- READER =
Shoji::Excel::Reader
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#each, foreach_hash, valid_content?
Constructor Details
#initialize(filename) ⇒ Excel
Returns a new instance of Excel.
42
43
44
|
# File 'lib/shoji/excel.rb', line 42
def initialize(filename)
@filename = filename
end
|
Class Method Details
.convert_to_hash(filename, opts = {}) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# 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 = []
= rows.shift
= opts_for_convert[:header] if opts_for_convert[:header]
rows.each do |row|
list << make_hash(, row)
end
list
end
|
.foreach(filename, opts = {}, &block) ⇒ Object
12
13
14
15
|
# 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
|
.row_size(filename, opts = {}) ⇒ Object
24
25
26
|
# File 'lib/shoji/excel.rb', line 24
def self.row_size(filename, opts = {})
READER.new(filename).row_size(opts)
end
|
.rows(filename, opts = {}) ⇒ Object
20
21
22
|
# File 'lib/shoji/excel.rb', line 20
def self.rows(filename, opts = {})
READER.new(filename).rows(opts)
end
|
.valid_file?(filename) ⇒ Boolean
16
17
18
|
# File 'lib/shoji/excel.rb', line 16
def self.valid_file?(filename)
READER.valid_file? filename
end
|
Instance Method Details
#convert_to_hash(opts = {}) ⇒ Object
58
59
60
|
# File 'lib/shoji/excel.rb', line 58
def convert_to_hash(opts = {})
self.class.convert_to_hash(@filename, opts)
end
|
#foreach(opts = {}, &block) ⇒ Object
46
47
48
|
# File 'lib/shoji/excel.rb', line 46
def foreach(opts = {}, &block)
self.class.foreach(@filename, opts, &block)
end
|
#row_size(opts = {}) ⇒ Object
55
56
57
|
# File 'lib/shoji/excel.rb', line 55
def row_size(opts = {})
self.class.row_size(@filename, opts)
end
|
#rows(opts = {}) ⇒ Object
52
53
54
|
# File 'lib/shoji/excel.rb', line 52
def rows(opts = {})
self.class.rows(@filename, opts)
end
|
#valid_file? ⇒ Boolean
49
50
51
|
# File 'lib/shoji/excel.rb', line 49
def valid_file?
self.class.valid_file? @filename
end
|