Class: Punchout::Fabricator

Inherits:
Object
  • Object
show all
Defined in:
lib/punchout/fabricator.rb

Instance Method Summary collapse

Constructor Details

#initialize(factory) ⇒ Fabricator

Returns a new instance of Fabricator.



5
6
7
8
# File 'lib/punchout/fabricator.rb', line 5

def initialize(factory)
  @puncher = Puncher.new
  @factory = factory
end

Instance Method Details

#add(matchable) ⇒ Object



10
11
12
# File 'lib/punchout/fabricator.rb', line 10

def add(matchable)
  @puncher.add(matchable)
end

#can_punch?(type) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/punchout/fabricator.rb', line 14

def can_punch?(type)
  true
end

#punch(type) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/punchout/fabricator.rb', line 18

def punch(type)

  if @puncher.can_punch?(type)
    @puncher.punch(type)
  else
    matchable = @factory.build(type)
    @puncher.add(matchable)
    matchable.thing
  end
end