Class: Shoji::Base
Class Method Summary collapse
- .foreach(filename, opts = {}, &block) ⇒ Object
- .foreach_hash(filename, opts = {}, &block) ⇒ Object
- .row_size(filename, opts = {}) ⇒ Object
- .rows(filename, opts = {}) ⇒ Object
- .valid_content?(content, opts = {}) ⇒ Boolean
- .valid_file?(filename, opts = {}) ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.foreach(filename, opts = {}, &block) ⇒ Object
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
8 |
# File 'lib/shoji/base.rb', line 8 def self.row_size(filename, opts = {}); raise NoMethodError.new; end |
.rows(filename, opts = {}) ⇒ Object
7 |
# File 'lib/shoji/base.rb', line 7 def self.rows(filename, opts = {}); raise NoMethodError.new; end |
.valid_content?(content, opts = {}) ⇒ 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
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 |