-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash.rb
42 lines (34 loc) · 817 Bytes
/
flash.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require_relative 'ui'
require 'csv'
class Game
attr_reader :deck
def initialize(deck)
@deck = deck
end
def guess?(card, guess)
guess == card.term
end
end
module Deck
def self.load(file, card_class)
cards = []
File.read(file).split("\n").each_slice(3) do |lines|
card = lines.select{|word|word != ""}
cards << {:term=>card.last, :definition=> card.first}
end
cards.map{|card| card_class.new(card)}
end
end
class Card
attr_reader :term, :definition
def initialize(hash)
@term = hash[:term]
@definition = hash[:definition]
end
end
puts "Enter the name of a file that you would like to load as a deck!"
file = gets.chomp
flashcard_game = Game.new(Deck.load(file, Card))
interface = Interface.new(flashcard_game)
puts interface.play!
#puts game