Class: FakerBot::Commands::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/fakerbot/commands/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Search

Returns a new instance of Search.



10
11
12
# File 'lib/fakerbot/commands/search.rb', line 10

def initialize(options)
  @options = options
end

Instance Method Details

#execute(input) ⇒ Object



14
15
16
17
# File 'lib/fakerbot/commands/search.rb', line 14

def execute(input)
  result = FakerBot::Bot.find(input)
  puts result.empty? ? not_found : tree(result).render
end

#not_foundObject



29
30
31
# File 'lib/fakerbot/commands/search.rb', line 29

def not_found
  "\n ☹️ Sorry, we couldn't find a match\n"
end

#tree(input) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/fakerbot/commands/search.rb', line 19

def tree(input)
  TTY::Tree.new do
    input.each do |faker, methods|
      node Pastel.new.green(faker.to_s) do
        methods.each { |m| leaf Pastel.new.cyan(m.to_s) }
      end
    end
  end
end