class Punchout::Puncher

Every {Punchable} has a {Puncher}, which keeps the details of implementation from littering the namespace of the {Punchable}

Public Class Methods

new() click to toggle source
# File lib/punchout/puncher.rb, line 8
def initialize
  @matchables = Matchables.new
end

Public Instance Methods

add(matchable) click to toggle source

Adds passed {Matchable} to the list of things this {Puncher} can punch

@param matchable [Matchable] a thing this puncher can match on and punch on behalf of @raise [StandardError] if matchable isn't a {Matchable}

# File lib/punchout/puncher.rb, line 19
def add(matchable)
  if !matchable.kind_of?(Matchable)
    raise
  end

  @matchables.add(matchable)
end
all() click to toggle source

@return [Array] all of the {::Class}es that can be produced by this {Puncher}

# File lib/punchout/puncher.rb, line 36
def all
  @matchables.all.map do |m|
    m.thing
  end
end
can_punch?(type) click to toggle source

Indicates whether passed {::Class} is something this {Puncher} would punch if stimulated appropriately

# File lib/punchout/puncher.rb, line 29
def can_punch?(type)
  @matchables.include?(type)
end
punch(type) click to toggle source
# File lib/punchout/puncher.rb, line 42
def punch(type)

  match = @matchables.find(type)

  if match
    match.thing
  end
end
punch!(type) click to toggle source
# File lib/punchout/puncher.rb, line 51
def punch!(type)
  punch(type) or raise
end