Class: CBHPMTable

Inherits:
Object
  • Object
show all
Defined in:
lib/cbhpm_table.rb,
lib/cbhpm_table/version.rb

Overview

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

Constant Summary collapse

VERSIONS =
{}
CBHPM3a =
VERSIONS[:cbhpm3a] =
    { file_basename: "CBHPM 2004 3¶ EDIÄ«O.XLS",
edition_name: "3a",
header_format: {
  0 => "code",
  1 => "name",
  4 => "cir_size",
  5 => "uco",
  6 => "aux_qty",
  7 => "an_size"
},
start_date: "01/01/2004",
end_date: "31/12/2005" }
CBHPM4a =
VERSIONS[:cbhpm4a] =
    { file_basename: "CBHPM  4¶ EDIÄ«O.xls",
edition_name: "4a",
header_format: {
  0 => "code",
  1 => "name",
  4 => "cir_size",
  5 => "uco",
  6 => "aux_qty",
  7 => "an_size"
},
start_date: "01/01/2006",
end_date: "31/12/2007" }
CBHPM5a =
VERSIONS[:cbhpm5a] =
    { file_basename: "CBHPM 5¶ Ediá∆o.xls",
edition_name: "5a",
header_format: {
  0 => "code",
  1 => "name",
  4 => "cir_size",
  5 => "uco",
  6 => "aux_qty",
  7 => "an_size"
},
start_date: "01/01/2008",
end_date: "31/12/2009" }
CBHPM2010 =
VERSIONS[:cbhpm2010] =
    { file_basename: "CBHPM 2010 separada.xls",
edition_name: "2010",
header_format: CBHPM5a[:header_format],
start_date: "01/01/2010",
end_date: "31/12/2011" }
CBHPM2012 =
VERSIONS[:cbhpm2012] =
    { file_basename: "CBHPM 2012.xlsx",
edition_name: "2012",
header_format: {
  4 => "code",
  5 => "name",
  8 => "cir_size",
  9 => "uco",
  10 => "aux_qty",
  11 => "an_size"
},
start_date: "01/01/2012",
end_date: nil }
VERSION_FOR_FILE =
{
"CBHPM 2004 3¶ EDIÄ«O.XLS" => CBHPM3a,
"CBHPM  4¶ EDIÄ«O.xls" => CBHPM4a,
"CBHPM 5¶ Ediá∆o.xls" => CBHPM5a,
"CBHPM 2010 separada.xls" => CBHPM2010,
"CBHPM 2012.xlsx" => CBHPM2012,
"cbhpm_cut_for_testing.xlsx" => CBHPM2012 }
ROO_CLASS_FOR_EXTENSION =
{ ".xls" => Roo::Excel, ".xlsx" => Roo::Excelx }
VERSION =
"0.0.6"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cbhpm_path, headers_hash = nil) ⇒ CBHPMTable

Returns a new instance of CBHPMTable.



30
31
32
33
34
35
36
37
# 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

Instance Attribute Details

#cbhpm_pathObject (readonly)

Returns the value of attribute cbhpm_path.



77
78
79
# File 'lib/cbhpm_table.rb', line 77

def cbhpm_path
  @cbhpm_path
end

#rooObject (readonly)

Returns the value of attribute roo.



28
29
30
# File 'lib/cbhpm_table.rb', line 28

def roo
  @roo
end

Instance Method Details

#each_rowObject



79
80
81
82
83
84
85
86
# 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_nameObject



65
66
67
# File 'lib/cbhpm_table.rb', line 65

def edition_name
  version_format[:edition_name]
end

#end_dateObject



100
101
102
# File 'lib/cbhpm_table.rb', line 100

def end_date
  version_format[:end_date]
end

#headersObject



39
40
41
# File 'lib/cbhpm_table.rb', line 39

def headers
  row(first_row_index)
end

#headers_hashObject



88
89
90
# File 'lib/cbhpm_table.rb', line 88

def headers_hash
  @headers_hash ||= fetch_headers_hash
end

#row(row_index) ⇒ Object



47
48
49
# File 'lib/cbhpm_table.rb', line 47

def row(row_index)
  import_row(roo.row(row_index))
end

#rowsObject



61
62
63
# File 'lib/cbhpm_table.rb', line 61

def rows
  each_row.to_a
end

#start_dateObject



96
97
98
# File 'lib/cbhpm_table.rb', line 96

def start_date
  version_format[:start_date]
end

#version_formatObject



69
70
71
# File 'lib/cbhpm_table.rb', line 69

def version_format
  @version_format ||= fetch_version_format
end