Class: Bmg::Reader::Excel
- Inherits:
-
Object
- Object
- Bmg::Reader::Excel
- Includes:
- Bmg::Reader
- Defined in:
- lib/bmg/reader/excel.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ skip: 0, row_num: true }
Instance Attribute Summary
Attributes included from Bmg::Reader
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, path, options = {}) ⇒ Excel
constructor
A new instance of Excel.
- #to_ast ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Methods included from Bmg::Relation
#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, path, options = {}) ⇒ Excel
Returns a new instance of Excel.
11 12 13 14 15 |
# File 'lib/bmg/reader/excel.rb', line 11 def initialize(type, path, = {}) @type = type @path = path @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#each ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bmg/reader/excel.rb', line 17 def each return to_enum unless block_given? require 'roo' xlsx = Roo::Spreadsheet.open(@path, @options) headers = nil xlsx.sheet(0) .each .drop(@options[:skip]) .each_with_index .each do |row, i| if i==0 headers = row.map{|c| c.to_s.strip.to_sym } else init = init_tuple(i) tuple = (0...headers.size) .each_with_object(init){|i,t| t[headers[i]] = row[i] } yield(tuple) end end end |
#to_ast ⇒ Object
40 41 42 |
# File 'lib/bmg/reader/excel.rb', line 40 def to_ast [ :excel, @path, @options ] end |
#to_s ⇒ Object Also known as: inspect
44 45 46 |
# File 'lib/bmg/reader/excel.rb', line 44 def to_s "(excel #{@path})" end |