Class: ClassMetrix::Formatters::Components::TableComponent::TableDataExtractor
- Inherits:
-
Object
- Object
- ClassMetrix::Formatters::Components::TableComponent::TableDataExtractor
- Defined in:
- lib/class_metrix/formatters/components/table_component/table_data_extractor.rb
Instance Method Summary collapse
- #behavior_column_index ⇒ Object
- #collect_hash_keys(values) ⇒ Object
- #extract_row_data(row) ⇒ Object
- #has_type_column? ⇒ Boolean
-
#initialize(headers) ⇒ TableDataExtractor
constructor
A new instance of TableDataExtractor.
- #row_has_expandable_hash?(row) ⇒ Boolean
- #value_start_index ⇒ Object
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_index ⇒ Object
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
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
39 40 41 42 43 44 |
# File 'lib/class_metrix/formatters/components/table_component/table_data_extractor.rb', line 39 def (row) values = row[value_start_index..] || [] return false if values.nil? values.any? { |cell| cell.is_a?(Hash) } end |
#value_start_index ⇒ Object
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 |