-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
h4 | |||
a3 |