Class: ObliqueStrategies

Inherits:
Object
  • Object
show all
Defined in:
lib/obs_deck/oblique_strategies.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

STRATEGY_DIR =
File.join(File.absolute_path(__dir__), '..', 'decks')
USER_DECK =
File.join(File.absolute_path(__dir__), '..', 'decks', 'user_deck.txt')

Instance Method Summary collapse

Constructor Details

#initialize(path: STRATEGY_DIR) ⇒ ObliqueStrategies

Returns a new instance of ObliqueStrategies.



7
8
9
# File 'lib/obs_deck/oblique_strategies.rb', line 7

def initialize(path: STRATEGY_DIR)
  @deck = load_decks
end

Instance Method Details

#add_a_card(path: USER_DECK) ⇒ Object



21
22
23
24
25
# File 'lib/obs_deck/oblique_strategies.rb', line 21

def add_a_card(path: USER_DECK)
  puts "Add your card or press Ctrl+C if you reconsider."
  prompt = gets.chomp
  File.open(path, 'a') { |f| f << "#{prompt}\n" }
end

#cardObject



27
28
29
# File 'lib/obs_deck/oblique_strategies.rb', line 27

def card
  @deck.sample
end

#infoObject



17
18
19
# File 'lib/obs_deck/oblique_strategies.rb', line 17

def info
  puts "Total number of cards in the deck: #{load_decks.size}"
end

#load_decksObject



11
12
13
14
15
# File 'lib/obs_deck/oblique_strategies.rb', line 11

def load_decks
  Dir.glob(File.join(STRATEGY_DIR, '*.txt')).flat_map do |file|
    File.readlines(file).map(&:chomp).map(&:strip)
  end
end