Module: OmniAI::Tools::Browser::Formatters::DataEntryFormatter
- Defined in:
- lib/omniai/tools/browser/formatters/data_entry_formatter.rb
Overview
Formats grouped elements for optimal data entry display
Class Method Summary collapse
- .build_header(total_count, text) ⇒ Object
- .find_context(input) ⇒ Object
- .find_meaningful_cell_text(row) ⇒ Object
- .find_table_context(input) ⇒ Object
- .format_actions_section(actions) ⇒ Object
- .format_control_group(name, controls) ⇒ Object
- .format_controls_section(form_controls) ⇒ Object
- .format_each_group(grouped_elements) ⇒ Object
- .format_form_controls(form_controls) ⇒ Object
- .format_groups(grouped_elements, total_count, text) ⇒ Object
- .format_inputs(inputs) ⇒ Object
- .format_inputs_section(inputs) ⇒ Object
- .format_labels(labels) ⇒ Object
- .format_labels_section(labels) ⇒ Object
- .format_single_group(inputs) ⇒ Object
- .format_table_groups(table_groups) ⇒ Object
- .group_by_table_context(inputs) ⇒ Object
- .humanize(text) ⇒ Object
Class Method Details
.build_header(total_count, text) ⇒ Object
41 42 43 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 41 def build_header(total_count, text) "Found #{total_count} elements containing '#{text}':\n\n" end |
.find_context(input) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 106 def find_context(input) table = input.ancestors("table").first return "Form Fields" unless table find_table_context(input) end |
.find_meaningful_cell_text(row) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 120 def find_meaningful_cell_text(row) meaningful_cell = row.css("td, th").find do |cell| cell.text.strip.length > 2 && !cell.text.match?(/^\d+\.?\d*$/) end meaningful_cell ? meaningful_cell.text.strip[0..30] : "Table" end |
.find_table_context(input) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 113 def find_table_context(input) row = input.ancestors("tr").first return "Table" unless row find_meaningful_cell_text(row) end |
.format_actions_section(actions) ⇒ Object
58 59 60 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 58 def format_actions_section(actions) actions.any? ? ActionFormatter.format_actions(actions) : "" end |
.format_control_group(name, controls) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 70 def format_control_group(name, controls) result = "\n #{name.humanize} options:\n" controls.each do |control| checked = control["checked"] ? " \u2713" : "" result += " • #{control['value']}#{checked}\n" end result end |
.format_controls_section(form_controls) ⇒ Object
62 63 64 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 62 def format_controls_section(form_controls) form_controls.any? ? format_form_controls(form_controls) : "" end |
.format_each_group(grouped_elements) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 45 def format_each_group(grouped_elements) [ format_inputs_section(grouped_elements[:inputs]), format_actions_section(grouped_elements[:actions]), format_controls_section(grouped_elements[:form_controls]), format_labels_section(grouped_elements[:labels]), ].join end |
.format_form_controls(form_controls) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 24 def format_form_controls(form_controls) result = "🎛️ Form Controls:\n" form_controls.each do |name, controls| result += format_control_group(name, controls) end result += "\n" end |
.format_groups(grouped_elements, total_count, text) ⇒ Object
11 12 13 14 15 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 11 def format_groups(grouped_elements, total_count, text) result = build_header(total_count, text) result += format_each_group(grouped_elements) result end |
.format_inputs(inputs) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 17 def format_inputs(inputs) result = "📝 Data Entry Fields:\n" table_groups = group_by_table_context(inputs) result += format_table_groups(table_groups) "#{result}\n" end |
.format_inputs_section(inputs) ⇒ Object
54 55 56 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 54 def format_inputs_section(inputs) inputs.any? ? format_inputs(inputs) : "" end |
.format_labels(labels) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 32 def format_labels(labels) result = "🏷️ Labels & Headers:\n" labels.first(3).each do |label| result += " • #{label.name}: #{label.text.strip}\n" end result += " ... and #{labels.size - 3} more\n" if labels.size > 3 result += "\n" end |
.format_labels_section(labels) ⇒ Object
66 67 68 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 66 def format_labels_section(labels) labels.any? ? format_labels(labels) : "" end |
.format_single_group(inputs) ⇒ Object
90 91 92 93 94 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 90 def format_single_group(inputs) result = "" inputs.each { |input| result += InputFormatter.format_input_field(input, " ") } result end |
.format_table_groups(table_groups) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 79 def format_table_groups(table_groups) return format_single_group(table_groups.values.first) if table_groups.size == 1 result = "" table_groups.each do |(context, group_inputs)| result += "\n #{context}:\n" group_inputs.each { |input| result += InputFormatter.format_input_field(input, " ") } end result end |
.group_by_table_context(inputs) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 96 def group_by_table_context(inputs) groups = {} inputs.each do |input| context = find_context(input) groups[context] ||= [] groups[context] << input end groups end |
.humanize(text) ⇒ Object
128 129 130 |
# File 'lib/omniai/tools/browser/formatters/data_entry_formatter.rb', line 128 def humanize(text) text.gsub(/[-_]/, " ").split.map(&:capitalize).join(" ") end |