Class: Enf::Elephant::FetchService

Inherits:
Object
  • Object
show all
Defined in:
lib/enf/elephant/fetch_service.rb

Overview

Pattern dectection service class

Constant Summary collapse

SEARCH_KEY_ERROR =
'key not found: %s'

Class Method Summary collapse

Class Method Details

.search_in(head, searched) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/enf/elephant/fetch_service.rb', line 7

def self.search_in(head, searched)
  elephant = head
  index = 0
  while index < searched.size
    elephant = elephant.children.fetch(searched[index]) do
      return yield if block_given?
      fail KeyError, SEARCH_KEY_ERROR % searched[index].inspect
    end
    index += 1
  end
  elephant
end