Class: Patience::EventHandler::Drop

Inherits:
Object
  • Object
show all
Includes:
Processable
Defined in:
lib/patience/event_handlers/drop.rb

Overview

Drop’s objects handles dropping of the cards. It means, that these objects decide, what to do with dropped card. For example, they can return a dropped card to its initial position, cancelling the work of drag event.

cursor.drop = EventHandler::Drop.new(click, areas)
# Execute scenario for the drop event,
# which calculates dynamically.
cursor.drop.scenario.call

Instance Attribute Summary collapse

Attributes included from Processable

#area, #card, #pile

Instance Method Summary collapse

Methods included from Processable

#detect_in, #find_area_in, #find_card_in, #find_pile_in, #foundation?, #nothing?, #pick_up, #something?, #stock?, #tableau?, #to_a, #to_h, #waste?

Constructor Details

#initialize(click, areas) ⇒ Drop

Returns a new instance of Drop.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/patience/event_handlers/drop.rb', line 19

def initialize(click, areas)
  @cards        = click.cards
  @areas        = areas
  @pile         = click.pile
  @card_to_drop = click.card

  @card_beneath = find_card_beneath
  @pile_beneath = find_pile_beneath
  @area         = find_area_beneath

  @scenario = -> {
    if tableau?
      put_in_tableau
    elsif foundation?
      put_in_foundation
    else
      call_off
    end
  }
end

Instance Attribute Details

#scenarioObject (readonly)

Returns the value of attribute scenario.



17
18
19
# File 'lib/patience/event_handlers/drop.rb', line 17

def scenario
  @scenario
end