Class: Tarot::Fortune

Inherits:
Object
  • Object
show all
Defined in:
lib/marxbot/tarot/fortune.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFortune

Returns a new instance of Fortune.



7
8
9
10
11
# File 'lib/marxbot/tarot/fortune.rb', line 7

def initialize()
  @deck = Card.deck_json
  @hand_size = 6
  @hand = draw_hand()
end

Instance Attribute Details

#deckObject (readonly)

Returns the value of attribute deck.



6
7
8
# File 'lib/marxbot/tarot/fortune.rb', line 6

def deck
  @deck
end

#handObject (readonly)

Returns the value of attribute hand.



6
7
8
# File 'lib/marxbot/tarot/fortune.rb', line 6

def hand
  @hand
end

#hand_sizeObject (readonly)

Returns the value of attribute hand_size.



6
7
8
# File 'lib/marxbot/tarot/fortune.rb', line 6

def hand_size
  @hand_size
end

Instance Method Details

#draw_handObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/marxbot/tarot/fortune.rb', line 13

def draw_hand()
  cards = []
  hand_size.times do |i|
    flipped = [true,false].sample
    card_data = deck.sample
    deck.reject!{|c| c == card_data}
    # binding.pry
    cards << Card.new(card_data, flipped)
  end

  return cards
end

#fortune_structuresObject



34
35
36
37
38
# File 'lib/marxbot/tarot/fortune.rb', line 34

def fortune_structures()
  lines = [
    "#{hand[0].adjective} #{hand[1].noun} #{maybe_word} #{hand[2].verb} #{link_word} #{hand[3].noun}"
  ]
end


40
41
42
# File 'lib/marxbot/tarot/fortune.rb', line 40

def link_word
  ["for", "because of", "thanks to", "and so", "thus, the"].sample
end

#maybe_wordObject



44
45
46
# File 'lib/marxbot/tarot/fortune.rb', line 44

def maybe_word
  ["will", "could", "shall", "ought to", "should"].sample
end

#tell_fortuneObject



26
27
28
29
30
31
32
# File 'lib/marxbot/tarot/fortune.rb', line 26

def tell_fortune()
  puts hand.map{|card| "#{card.flipped} #{card.name}"}
  return {
    cards: hand,
    result: fortune_structures.sample
  }
end