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

Constructor Details

#initialize(search) ⇒ PrintItems

Returns a new instance of PrintItems.



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

def initialize(search)
  @search = search
end

Instance Attribute Details

#searchObject (readonly)

Returns the value of attribute search.



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

def search
  @search
end

Instance Method Details

#filter_by_search(items) ⇒ Object



20
21
22
23
24
# File 'lib/flatito/print_items.rb', line 20

def filter_by_search(items)
  items.select do |item|
    regex.match?(item.key)
  end
end


12
13
14
15
16
17
18
# File 'lib/flatito/print_items.rb', line 12

def print(items, pathname = nil)
  items = filter_by_search(items) if search
  return unless items.any?

  renderer.print_pathname(pathname) if pathname
  renderer.print_items(items)
end

#rendererObject



26
27
28
# File 'lib/flatito/print_items.rb', line 26

def renderer
  Config.renderer
end