Class: Flatito::PrintItems

Inherits:
Object
  • Object
show all
Includes:
RegexFromSearch
Defined in:
lib/flatito/print_items.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RegexFromSearch

#regex, #value_regex

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_sensitiveObject (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

#searchObject (readonly)

Returns the value of attribute search.



7
8
9
# File 'lib/flatito/print_items.rb', line 7

def search
  @search
end

#search_valueObject (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

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