SgfParser 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ # With this code, we will display info on all files within a directory:
2
+ # "Black_player-White_player.sgf"
3
+
4
+ require '../lib/sgf_parser'
5
+
6
+
7
+ Dir.glob('../sample_sgf/*').each do |file|
8
+ next if File.directory? file # Let's not touch directories.
9
+ next if File.extname(file) != ".sgf" # If it's not an SGF file, let's not touch it.
10
+ sgf = SgfParser::Tree.new :filename => file
11
+ # The "root" is an empty node, always, so we can support SGF collections painlessly:
12
+ # Whole trees simply become branches from the root.
13
+
14
+ black = sgf.root.children[0].PB rescue "Black" # Alright, so this isn't particularly elegant.
15
+ white = sgf.root.children[0].PW rescue "White" # It's a work in progress !
16
+
17
+ puts "#{black}-#{white}.sgf"
18
+
19
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SgfParser::Node" do
4
+ before :each do
5
+ @node = SgfParser::Node.new
6
+ end
7
+
8
+ it "should be a valid node" do
9
+ @node.class.should == SgfParser::Node
10
+ @node.properties.should == {}
11
+ @node.parent.should == nil
12
+ @node.children.should == []
13
+ end
14
+
15
+ it "should store properties" do
16
+ @node.add_properties "PB" => "Dosaku"
17
+ @node.properties.should == {"PB" => "Dosaku"}
18
+ end
19
+
20
+ it "should link to a parent" do
21
+ parent = SgfParser::Node.new
22
+ @node.parent = parent
23
+ @node.parent.should == parent
24
+ end
25
+
26
+ it "should link to children" do
27
+ child1 = SgfParser::Node.new
28
+ child2 = SgfParser::Node.new
29
+ child3 = SgfParser::Node.new
30
+ @node.add_children child1, child2, child3
31
+ @node.children.should == [child1, child2, child3]
32
+ end
33
+
34
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'sgf_parser'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SgfParser::Tree" do
4
+
5
+ before :each do
6
+ @tree = SgfParser::Tree.new :filename => 'sample_sgf/ff4_ex.sgf'
7
+ end
8
+
9
+ it "should parse properly" do
10
+ @tree.class.should == SgfParser::Tree
11
+ @tree.root.children.size.should == 2
12
+ @tree.root.children[0].children.size.should == 5
13
+ end
14
+
15
+ it "should save properly" do
16
+ @new = 'sample_sgf/ff4_ex_saved.sgf'
17
+ @tree.save :filename => @new
18
+ @tree2 = SgfParser::Tree.new :filename => @new
19
+
20
+ @tree2.should == @tree
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SgfParser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Aldric Giacomoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-05 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: SGFParser is a library that parses and saves SGF (Smart Game Format) files.
26
+ email: aldric@trevoke.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - SgfParser.gemspec
41
+ - VERSION
42
+ - lib/sgf/parser/node.rb
43
+ - lib/sgf/parser/properties.rb
44
+ - lib/sgf/parser/tree.rb
45
+ - lib/sgf/parser/tree_parse.rb
46
+ - lib/sgf/sgfindent.rb
47
+ - lib/sgf_parser.rb
48
+ - sample_sgf/ff4_ex.sgf
49
+ - sample_sgf/ff4_ex_saved.sgf
50
+ - sample_sgf/redrose-tartrate.sgf
51
+ - sample_usage/parsing_files.rb
52
+ - spec/node_spec.rb
53
+ - spec/spec.opts
54
+ - spec/spec_helper.rb
55
+ - spec/tree_spec.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/Trevoke/SGFParser
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: A library for working with SGF files.
84
+ test_files:
85
+ - spec/node_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/tree_spec.rb