Class: Punchout::Puncher
- Inherits:
-
Object
- Object
- Punchout::Puncher
- Defined in:
- lib/punchout/puncher.rb,
lib/punchout/puncher/matchable.rb,
lib/punchout/puncher/matchables.rb
Overview
Defined Under Namespace
Classes: Matchable, Matchables
Instance Method Summary collapse
- #add(matchable) ⇒ Object
-
#all ⇒ Array
All of the Classes that can be produced by this Puncher.
-
#can_punch?(type) ⇒ Boolean
Indicates whether passed Class is something this Puncher would punch if stimulated appropriately.
-
#initialize ⇒ Puncher
constructor
A new instance of Puncher.
- #punch(type) ⇒ Object
- #punch!(type) ⇒ Object
Constructor Details
#initialize ⇒ Puncher
Returns a new instance of Puncher.
8 9 10 |
# File 'lib/punchout/puncher.rb', line 8 def initialize @matchables = Matchables.new end |
Instance Method Details
#add(matchable) ⇒ Object
Adds passed Matchable to the list of things this Punchout::Puncher can punch
on behalf of
19 20 21 22 23 24 25 |
# File 'lib/punchout/puncher.rb', line 19 def add(matchable) if !matchable.kind_of?(Matchable) raise end @matchables.add(matchable) end |
#all ⇒ Array
Returns all of the Classes that can be produced by this Punchout::Puncher.
36 37 38 39 40 |
# File 'lib/punchout/puncher.rb', line 36 def all @matchables.all.map do |m| m.thing end end |
#can_punch?(type) ⇒ Boolean
Indicates whether passed Class is something this Punchout::Puncher would punch if stimulated appropriately
29 30 31 |
# File 'lib/punchout/puncher.rb', line 29 def can_punch?(type) @matchables.include?(type) end |
#punch(type) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/punchout/puncher.rb', line 42 def punch(type) match = @matchables.find(type) if match match.thing end end |
#punch!(type) ⇒ Object
51 52 53 |
# File 'lib/punchout/puncher.rb', line 51 def punch!(type) punch(type) or raise end |