Class: Shoji::ODS

Inherits:
Base
  • Object
show all
Defined in:
lib/shoji/ods.rb

Defined Under Namespace

Classes: Reader

Constant Summary collapse

READER =
Shoji::ODS::Reader

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#each, foreach_hash, valid_content?

Constructor Details

#initialize(filename) ⇒ ODS

Returns a new instance of ODS.



41
42
43
# File 'lib/shoji/ods.rb', line 41

def initialize(filename)
  @filename = filename
end

Class Method Details

.convert_to_hash(filename, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shoji/ods.rb', line 27

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) ⇒ Object



9
10
11
12
13
14
# File 'lib/shoji/ods.rb', line 9

def self.foreach(filename, opts = {}, &block)
  raise 'Block must be exist.' unless block_given?
  READER.open(filename, opts[:sheet]) do |row|
    block.call(row)
  end
end

.row_size(filename, opts = {}) ⇒ Object



23
24
25
# File 'lib/shoji/ods.rb', line 23

def self.row_size(filename, opts = {})
  READER.new(filename).row_size(opts)
end

.rows(filename, opts = {}) ⇒ Object



19
20
21
# File 'lib/shoji/ods.rb', line 19

def self.rows(filename, opts = {})
  READER.new(filename).rows(opts)
end

.valid_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/shoji/ods.rb', line 15

def self.valid_file?(filename)
  READER.valid_file? filename
end

Instance Method Details

#convert_to_hash(opts = {}) ⇒ Object



57
58
59
# File 'lib/shoji/ods.rb', line 57

def convert_to_hash(opts = {})
  self.class.convert_to_hash(@filename, opts)
end

#foreach(opts = {}, &block) ⇒ Object



45
46
47
# File 'lib/shoji/ods.rb', line 45

def foreach(opts = {}, &block)
  self.class.foreach(@filename, opts, &block)
end

#row_size(opts = {}) ⇒ Object



54
55
56
# File 'lib/shoji/ods.rb', line 54

def row_size(opts = {})
  self.class.row_size(@filename, opts)
end

#rows(opts = {}) ⇒ Object



51
52
53
# File 'lib/shoji/ods.rb', line 51

def rows(opts = {})
  self.class.rows(@filename, opts)
end

#valid_file?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/shoji/ods.rb', line 48

def valid_file?
  self.class.valid_file? @filename
end