Class: Shoji::Base

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/shoji/base.rb

Direct Known Subclasses

Excel, ODS, TextBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

Raises:

  • (NoMethodError)


5
# File 'lib/shoji/base.rb', line 5

def self.foreach(filename, opts = {}, &block); raise NoMethodError.new; end

.foreach_hash(filename, opts = {}, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/shoji/base.rb', line 21

def self.foreach_hash(filename, opts = {}, &block)
  header = nil
  self.foreach(filename, opts) do |row|
    if header
      hash = Hash[*[header, row].transpose.flatten]
      block.call(hash)
    else
      header = row.map(&:to_sym)
    end
  end
end

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

Raises:

  • (NoMethodError)


8
# File 'lib/shoji/base.rb', line 8

def self.row_size(filename, opts = {}); raise NoMethodError.new; end

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

Raises:

  • (NoMethodError)


7
# File 'lib/shoji/base.rb', line 7

def self.rows(filename, opts = {}); raise NoMethodError.new; end

.valid_content?(content, opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.valid_content?(content, opts = {})
  tf = Tempfile.new("shoji-base.#{$$}.data")
  tf.write content
  tf.close
  status = self.valid_file?(tf.path)
  tf.close(true)
  status
end

.valid_file?(filename, opts = {}) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)


6
# File 'lib/shoji/base.rb', line 6

def self.valid_file?(filename, opts = {}); raise NoMethodError.new; end

Instance Method Details

#each(&block) ⇒ Object



18
19
20
# File 'lib/shoji/base.rb', line 18

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