Permalink
Browse files

first commit

  • Loading branch information...
1 parent e5c07e1 commit f864a25e21d65eaa7efd647f4616962414550ac8 @smtalim committed Oct 2, 2011
Showing with 50 additions and 0 deletions.
  1. +41 −0 chess_opener.rb
  2. +7 −0 chess_opener_test.rb
  3. +2 −0 chess_opener_test.txt
View
@@ -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
@@ -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])
@@ -0,0 +1,2 @@
+h4
+a3

0 comments on commit f864a25

Please sign in to comment.