Class: Yarr::Command::Fake

Inherits:
Base
  • Object
show all
Extended by:
Concern::ASTDigger
Defined in:
lib/yarr/command/fake.rb

Overview

Exposing the faker gem as a bot command

Instance Attribute Summary

Attributes inherited from Base

#ast, #irc

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concern::ASTDigger

digger

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Yarr::Command::Base

Class Method Details

.match?(ast) ⇒ True|False

Returns can this command handle the AST?.

Parameters:

  • ast (AST)

    parsed ast

Returns:

  • (True|False)

    can this command handle the AST?


15
16
17
# File 'lib/yarr/command/fake.rb', line 15

def self.match?(ast)
  ast[:command] == 'fake' && ast.key?(:class_method)
end

Instance Method Details

#handleObject

Runs the command


20
21
22
23
24
25
26
# File 'lib/yarr/command/fake.rb', line 20

def handle
  Faker.const_get(class_name).send(method_name).to_s
rescue NameError
  'No suitable faker found. The list is at ' \
  'https://github.com/stympy/faker with the restriction that I need ' \
  'Classname.methodname.'
end