Class: HammerCLI::Output::FieldFilter
- Inherits:
-
Object
- Object
- HammerCLI::Output::FieldFilter
- Defined in:
- lib/hammer_cli/output/field_filter.rb
Instance Attribute Summary collapse
-
#classes_filter ⇒ Object
Returns the value of attribute classes_filter.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#filtered_fields ⇒ Object
readonly
Returns the value of attribute filtered_fields.
-
#sets_filter ⇒ Object
Returns the value of attribute sets_filter.
Instance Method Summary collapse
- #filter_by_classes(classes = nil) ⇒ Object
- #filter_by_data(data, compact_only: false) ⇒ Object
- #filter_by_sets(sets = nil) ⇒ Object
-
#initialize(fields = [], filters = {}) ⇒ FieldFilter
constructor
A new instance of FieldFilter.
Constructor Details
#initialize(fields = [], filters = {}) ⇒ FieldFilter
Returns a new instance of FieldFilter.
6 7 8 9 10 |
# File 'lib/hammer_cli/output/field_filter.rb', line 6 def initialize(fields = [], filters = {}) self.fields = fields @classes_filter = filters[:classes_filter] || [] @sets_filter = filters[:sets_filter] || [] end |
Instance Attribute Details
#classes_filter ⇒ Object
Returns the value of attribute classes_filter.
4 5 6 |
# File 'lib/hammer_cli/output/field_filter.rb', line 4 def classes_filter @classes_filter end |
#fields ⇒ Object
Returns the value of attribute fields.
3 4 5 |
# File 'lib/hammer_cli/output/field_filter.rb', line 3 def fields @fields end |
#filtered_fields ⇒ Object (readonly)
Returns the value of attribute filtered_fields.
3 4 5 |
# File 'lib/hammer_cli/output/field_filter.rb', line 3 def filtered_fields @filtered_fields end |
#sets_filter ⇒ Object
Returns the value of attribute sets_filter.
4 5 6 |
# File 'lib/hammer_cli/output/field_filter.rb', line 4 def sets_filter @sets_filter end |
Instance Method Details
#filter_by_classes(classes = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/hammer_cli/output/field_filter.rb', line 17 def filter_by_classes(classes = nil) classes ||= @classes_filter classes.each do |cls| @filtered_fields.reject! do |f| f.is_a? cls end end self end |
#filter_by_data(data, compact_only: false) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/hammer_cli/output/field_filter.rb', line 36 def filter_by_data(data, compact_only: false) @filtered_fields = displayable_fields(@filtered_fields, data, compact_only: compact_only) self end |
#filter_by_sets(sets = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/hammer_cli/output/field_filter.rb', line 27 def filter_by_sets(sets = nil) sets ||= @sets_filter return self if sets.empty? set_names, labels = resolve_set_names(sets) deep_filter(@filtered_fields, set_names, labels) self end |