Module: Strata::CLI::TableFilter
- Defined in:
- lib/strata/cli/helpers/table_filter.rb
Overview
Shared module for table filtering and display name extraction
Class Method Summary collapse
-
.display_name(table_path) ⇒ String
Extract display name from full table path e.g., “sales/analytics/customer” -> “customer”.
-
.filter(tables, pattern) ⇒ Array<String>
Filter tables by pattern (case-insensitive).
-
.paginate(items, page: 1, per_page: 10) ⇒ Array
Paginate array of items.
-
.total_pages(items, per_page: 10) ⇒ Integer
Get total pages for pagination.
Class Method Details
.display_name(table_path) ⇒ String
Extract display name from full table path e.g., “sales/analytics/customer” -> “customer”
11 12 13 |
# File 'lib/strata/cli/helpers/table_filter.rb', line 11 def self.display_name(table_path) table_path.split("/").last || table_path end |
.filter(tables, pattern) ⇒ Array<String>
Filter tables by pattern (case-insensitive)
19 20 21 22 23 24 |
# File 'lib/strata/cli/helpers/table_filter.rb', line 19 def self.filter(tables, pattern) return tables if pattern.nil? || pattern.empty? regex = Regexp.new(pattern, Regexp::IGNORECASE) tables.select { |table| table.match?(regex) || display_name(table).match?(regex) } end |
.paginate(items, page: 1, per_page: 10) ⇒ Array
Paginate array of items
31 32 33 34 35 |
# File 'lib/strata/cli/helpers/table_filter.rb', line 31 def self.paginate(items, page: 1, per_page: 10) start_idx = (page - 1) * per_page end_idx = start_idx + per_page items[start_idx...end_idx] || [] end |
.total_pages(items, per_page: 10) ⇒ Integer
Get total pages for pagination
41 42 43 44 45 |
# File 'lib/strata/cli/helpers/table_filter.rb', line 41 def self.total_pages(items, per_page: 10) return 1 if items.empty? (items.length.to_f / per_page).ceil end |