class CBHPMTable
CBHPMTable:
cbhpm_table = CBHPMTable.new
“CBHPM 2012.xlsx”
cbhpm_table.headers
#=> { "code"=>"ID do Procedimento", "name"=>"Descrição do Procedimento", "cir_size"=>nil, "uco"=>"Custo Operac.", "aux_qty"=>"Nº de Aux.", "an_size"=>"Porte Anestés." }
cbhpm_table.row(2)
#=> { "code"=>"10101012", "name"=>"Em consultório (no horário normal ou preestabelecido)", "cir_size"=>"2B", "uco"=>nil, "aux_qty"=>nil, "an_size"=>nil}) }
cbhpm_table.rows
#=> # Returns an Array of Rows (as individual Hashes)
cbhpm_table.each_row do |row|
# do whatever with the row
end
Constants
- CBHPM2010
- CBHPM2012
- CBHPM2014
- CBHPM3a
- CBHPM4a
- CBHPM5a
- ROO_CLASS_FOR_EXTENSION
- VERSION
- VERSIONS
- VERSION_FOR_FILE
Attributes
cbhpm_path[R]
roo[R]
Public Class Methods
new(cbhpm_path, headers_hash = nil)
click to toggle source
# File lib/cbhpm_table.rb, line 30 def initialize(cbhpm_path, headers_hash = nil) @cbhpm_path = cbhpm_path roo_class = ROO_CLASS_FOR_EXTENSION[File.extname(cbhpm_path)] @roo = roo_class.new(cbhpm_path) @headers_hash = headers_hash || fetch_headers_hash fail "Can't find predefined headers for #{cbhpm_path}" unless @headers_hash end
Public Instance Methods
each_row() { |import_row(next)| ... }
click to toggle source
# File lib/cbhpm_table.rb, line 79 def each_row return to_enum(:each_row) unless block_given? roo_enum = roo.to_enum(:each) _skip_header = roo_enum.next loop do yield import_row(roo_enum.next) end end
edition_name()
click to toggle source
# File lib/cbhpm_table.rb, line 65 def edition_name version_format[:edition_name] end
end_date()
click to toggle source
# File lib/cbhpm_table.rb, line 100 def end_date version_format[:end_date] end
headers()
click to toggle source
# File lib/cbhpm_table.rb, line 39 def headers row(first_row_index) end
headers_hash()
click to toggle source
# File lib/cbhpm_table.rb, line 88 def headers_hash @headers_hash ||= fetch_headers_hash end
row(row_index)
click to toggle source
# File lib/cbhpm_table.rb, line 47 def row(row_index) import_row(roo.row(row_index)) end
rows()
click to toggle source
# File lib/cbhpm_table.rb, line 61 def rows each_row.to_a end
start_date()
click to toggle source
# File lib/cbhpm_table.rb, line 96 def start_date version_format[:start_date] end
version_format()
click to toggle source
# File lib/cbhpm_table.rb, line 69 def version_format @version_format ||= fetch_version_format end
Private Instance Methods
fetch_headers_hash()
click to toggle source
# File lib/cbhpm_table.rb, line 92 def fetch_headers_hash version_format[:header_format] end
fetch_version_format()
click to toggle source
# File lib/cbhpm_table.rb, line 73 def fetch_version_format VERSION_FOR_FILE[File.basename(cbhpm_path)] end
first_row_index()
click to toggle source
# File lib/cbhpm_table.rb, line 43 def first_row_index roo.first_row end
import_row(row_array)
click to toggle source
# File lib/cbhpm_table.rb, line 51 def import_row(row_array) imported_row = {} headers_hash.each do |col, name| imported_row[name] = row_array[col] end imported_row end