Class: ClassMetrix::Formatters::Components::TableComponent::TableDataExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/class_metrix/formatters/components/table_component/table_data_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ TableDataExtractor

Returns a new instance of TableDataExtractor.



8
9
10
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 8

def initialize(headers)
  @headers = headers
end

Instance Method Details

#behavior_column_indexObject



20
21
22
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 20

def behavior_column_index
  has_type_column? ? 1 : 0
end

#collect_hash_keys(values) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 46

def collect_hash_keys(values)
  all_hash_keys = Set.new
  values.each do |value|
    all_hash_keys.merge(value.keys.map(&:to_s)) if value.is_a?(Hash)
  end
  all_hash_keys
end

#extract_row_data(row) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 24

def extract_row_data(row)
  if has_type_column?
    {
      type_value: row[0],
      behavior_name: row[1],
      values: row[2..]
    }
  else
    {
      behavior_name: row[0],
      values: row[1..]
    }
  end
end

#has_type_column?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 12

def has_type_column?
  @headers.first == "Type"
end

#row_has_expandable_hash?(row) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 39

def row_has_expandable_hash?(row)
  values = row[value_start_index..] || []
  return false if values.nil?

  values.any? { |cell| cell.is_a?(Hash) }
end

#value_start_indexObject



16
17
18
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 16

def value_start_index
  has_type_column? ? 2 : 1
end