Class: KeywordSearch::Definition::Keyword

Inherits:
Object
  • Object
show all
Defined in:
lib/keyword_search/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description = nil, &handler) ⇒ Keyword

Returns a new instance of Keyword.



8
9
10
11
# File 'lib/keyword_search/definition.rb', line 8

def initialize(name, description=nil, &handler)
  @name, @description = name, description
  @handler = handler
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/keyword_search/definition.rb', line 7

def description
  @description
end

#handlerObject (readonly)

Returns the value of attribute handler.



7
8
9
# File 'lib/keyword_search/definition.rb', line 7

def handler
  @handler
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/keyword_search/definition.rb', line 7

def name
  @name
end

Instance Method Details

#handle(value, sign) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/keyword_search/definition.rb', line 13

def handle(value, sign)
  # If the handler is only expecting one argument,
  # only give them the positive matches
  if handler.arity == 1
    handler.call(value) if sign
  else
    handler.call(value, sign)
  end
end