Class: HXL::HXLTableSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/hxl/hxl_table_spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHXLTableSpec

Table metadata for parsing a HXL dataset



7
8
9
# File 'lib/hxl/hxl_table_spec.rb', line 7

def initialize
  @col_specs = []
end

Instance Attribute Details

#col_specsObject (readonly)

Returns the value of attribute col_specs.



3
4
5
# File 'lib/hxl/hxl_table_spec.rb', line 3

def col_specs
  @col_specs
end

Instance Method Details

#get_disaggregation_countObject



31
32
33
# File 'lib/hxl/hxl_table_spec.rb', line 31

def get_disaggregation_count
  (@col_specs.select { |col_spec| col_spec.fixed_column }).length
end

#get_raw_position(disaggregation_position) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/hxl/hxl_table_spec.rb', line 35

def get_raw_position(disaggregation_position)
  @col_specs.each_with_index do |col_spec, i|
    disaggregation_position -= 1 if col_spec.fixed_column

    return i if disaggregation_position < 0
  end

  return -1
end

#hxl_headersObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hxl/hxl_table_spec.rb', line 15

def hxl_headers
  headers = []
  seen_fixed = false
  @col_specs.each do |spec|
    if spec.fixed_column && !seen_fixed
      headers.push spec.fixed_column.hxl_tag
      headers.push spec.column.hxl_tag unless spec.column.hxl_tag.nil?
      seen_fixed = true
    elsif !spec.fixed_column
      headers.push spec.column.hxl_tag unless spec.column.hxl_tag.nil?
    end
  end

  headers
end

#push(col_spec) ⇒ Object



11
12
13
# File 'lib/hxl/hxl_table_spec.rb', line 11

def push(col_spec)
  @col_specs.push col_spec
end