Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
smtalim committed Oct 2, 2011
1 parent e5c07e1 commit f864a25
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions chess_opener.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,41 @@
class ChessOpener
def initialize
@data = {}
load_data
end

def self.load(filename)
dsl = new
dsl.instance_eval(File.read(filename))
end

def h4
puts "=========="
puts @data.assoc("h4")
puts "=========="
end

def a3
puts "=========="
puts @data.assoc("a3")
puts "=========="
end

def method_missing(method_name, *args, &block)
msg = "You tried to call the method #{method_name}. There is no such method."
raise msg
end

private
def load_data
@data = {"a3" => ["Anderssen's Opening Polish Gambit: 1. a3 a5 2. b4",
"Anderssen's Opening Creepy Crawly Formation: 1. a3 e5 2. h3 d5",
"Anderssen's Opening Andersspike: 1. a3 g6 2. g4"],
"h4" => ["Koola-Koola continues 1.h4 a5",
"Wulumulu continues 1.h4 e5 2. d4",
"Crab Variation continues 1.h4 any 2. a4",
"Borg Gambit continues 1.h4 g5.",
"Symmetric Variation continues 1.h4 h5"]}
end

end
7 changes: 7 additions & 0 deletions chess_opener_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative 'chess_opener'

if (ARGV.length != 1)
puts("Run the program as: ruby chess_opener_test.rb chess_opener_test.txt")
exit(1)
end
my_dsl = ChessOpener.load(ARGV[0])
2 changes: 2 additions & 0 deletions chess_opener_test.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
h4
a3

0 comments on commit f864a25

Please sign in to comment.