Class: Flatito::PrintItems
- Inherits:
-
Object
- Object
- Flatito::PrintItems
- Includes:
- RegexFromSearch
- Defined in:
- lib/flatito/print_items.rb
Instance Attribute Summary collapse
-
#case_sensitive ⇒ Object
readonly
Returns the value of attribute case_sensitive.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
-
#search_value ⇒ Object
readonly
Returns the value of attribute search_value.
Instance Method Summary collapse
- #filter_by_search(items) ⇒ Object
- #filter_by_value(items) ⇒ Object
-
#initialize(search, search_value = nil, case_sensitive: false) ⇒ PrintItems
constructor
A new instance of PrintItems.
-
#print(items, pathname = nil) ⇒ Object
rubocop:disable Naming/PredicateMethod.
Methods included from RegexFromSearch
Constructor Details
#initialize(search, search_value = nil, case_sensitive: false) ⇒ PrintItems
Returns a new instance of PrintItems.
9 10 11 12 13 |
# File 'lib/flatito/print_items.rb', line 9 def initialize(search, search_value = nil, case_sensitive: false) @search = search @search_value = search_value @case_sensitive = case_sensitive end |
Instance Attribute Details
#case_sensitive ⇒ Object (readonly)
Returns the value of attribute case_sensitive.
7 8 9 |
# File 'lib/flatito/print_items.rb', line 7 def case_sensitive @case_sensitive end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
7 8 9 |
# File 'lib/flatito/print_items.rb', line 7 def search @search end |
#search_value ⇒ Object (readonly)
Returns the value of attribute search_value.
7 8 9 |
# File 'lib/flatito/print_items.rb', line 7 def search_value @search_value end |
Instance Method Details
#filter_by_search(items) ⇒ Object
25 26 27 28 29 |
# File 'lib/flatito/print_items.rb', line 25 def filter_by_search(items) items.select do |item| regex.match?(item.key) end end |
#filter_by_value(items) ⇒ Object
31 32 33 34 35 |
# File 'lib/flatito/print_items.rb', line 31 def filter_by_value(items) items.select do |item| value_regex.match?(item.value) end end |
#print(items, pathname = nil) ⇒ Object
rubocop:disable Naming/PredicateMethod
15 16 17 18 19 20 21 22 23 |
# File 'lib/flatito/print_items.rb', line 15 def print(items, pathname = nil) # rubocop:disable Naming/PredicateMethod items = filter_by_search(items) if search items = filter_by_value(items) if search_value return false unless items.any? renderer.print_pathname(pathname) if pathname renderer.print_items(items) true end |