SgfParser 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.rdoc +44 -38
- data/SgfParser.gemspec +17 -15
- data/VERSION +1 -1
- data/lib/sgf.rb +8 -0
- data/lib/sgf/{sgf_indent.rb → indenter.rb} +108 -108
- data/lib/sgf/{parser/node.rb → node.rb} +61 -57
- data/lib/sgf/{parser/tree_parse.rb → parser.rb} +120 -111
- data/lib/sgf/{parser/properties.rb → properties.rb} +97 -97
- data/lib/sgf/{parser/tree.rb → tree.rb} +91 -107
- data/sample_usage/parsing_files.rb +18 -18
- data/{sample_sgf → spec/data}/ff4_ex.sgf +0 -0
- data/{sample_sgf → spec/data}/ff4_ex_saved.sgf +0 -0
- data/{sample_sgf → spec/data}/redrose-tartrate.sgf +1068 -1068
- data/{sample_sgf → spec/data}/simple.sgf +11 -11
- data/spec/data/simple_saved.sgf +7 -0
- data/spec/node_spec.rb +63 -33
- data/spec/parser_spec.rb +20 -0
- data/spec/spec_helper.rb +6 -6
- data/spec/tree_spec.rb +29 -41
- metadata +69 -87
- data/lib/sgf/sgfindent.rb +0 -118
- data/lib/sgf_parser.rb +0 -8
- data/sample_sgf/simple_saved.sgf +0 -7
- data/spec/tree_parser_spec.rb +0 -24
@@ -1,11 +1,11 @@
|
|
1
|
-
(;GM[1]FF[4]CA[UTF-8]
|
2
|
-
SZ[19]RU[Japanese]KM[0.50]TM[1290]OT[3x30 byo-yomi]
|
3
|
-
PB[tartrate]PW[redrose]BR[7d]WR[1p]DT[2003-06-18]PC[The Kiseido Go Server (KGS) at http://kgs.kiseido.com/]C[tartrate [7d?\]: hi
|
4
|
-
tartrate [7d?\]: thx
|
5
|
-
]RE[B+Resign]
|
6
|
-
;B[jj]BL[1280.503]CR[jj]C[redrose [1p\]: hi
|
7
|
-
Jerk [7d?\]: wow
|
8
|
-
Anark [11k\]: game of the day :)
|
9
|
-
Jerk [7d?\]: really big match
|
10
|
-
]
|
11
|
-
;W[ih]WL[1277.190]CR[ih];AB[aa][bb][cc])
|
1
|
+
(;GM[1]FF[4]CA[UTF-8]
|
2
|
+
SZ[19]RU[Japanese]KM[0.50]TM[1290]OT[3x30 byo-yomi]
|
3
|
+
PB[tartrate]PW[redrose]BR[7d]WR[1p]DT[2003-06-18]PC[The Kiseido Go Server (KGS) at http://kgs.kiseido.com/]C[tartrate [7d?\]: hi
|
4
|
+
tartrate [7d?\]: thx
|
5
|
+
]RE[B+Resign]
|
6
|
+
;B[jj]BL[1280.503]CR[jj]C[redrose [1p\]: hi
|
7
|
+
Jerk [7d?\]: wow
|
8
|
+
Anark [11k\]: game of the day :)
|
9
|
+
Jerk [7d?\]: really big match
|
10
|
+
]
|
11
|
+
;W[ih]WL[1277.190]CR[ih];AB[aa][bb][cc])
|
@@ -0,0 +1,7 @@
|
|
1
|
+
(;GM[1]FF[4]CA[UTF-8]SZ[19]RU[Japanese]KM[0.50]TM[1290]OT[3x30 byo-yomi]PB[tartrate]PW[redrose]BR[7d]WR[1p]DT[2003-06-18]PC[The Kiseido Go Server (KGS) at http://kgs.kiseido.com/]C[tartrate [7d?\]: hi
|
2
|
+
tartrate [7d?\]: thx
|
3
|
+
]RE[B+Resign];B[jj]BL[1280.503]CR[jj]C[redrose [1p\]: hi
|
4
|
+
Jerk [7d?\]: wow
|
5
|
+
Anark [11k\]: game of the day :)
|
6
|
+
Jerk [7d?\]: really big match
|
7
|
+
];W[ih]WL[1277.190]CR[ih];))
|
data/spec/node_spec.rb
CHANGED
@@ -1,34 +1,64 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "SgfParser::Node" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@node.
|
11
|
-
@node.
|
12
|
-
@node.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@node.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@node.parent
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@node.
|
32
|
-
|
33
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SgfParser::Node" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@node = SGF::Node.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be a valid node" do
|
10
|
+
@node.class.should == SGF::Node
|
11
|
+
@node.properties.should == {}
|
12
|
+
@node.parent.should == nil
|
13
|
+
@node.children.should == []
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should store properties" do
|
17
|
+
@node.add_properties "PB" => "Dosaku"
|
18
|
+
@node.properties.should == {"PB" => "Dosaku"}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should link to a parent" do
|
22
|
+
parent = SGF::Node.new
|
23
|
+
@node.parent = parent
|
24
|
+
@node.parent.should == parent
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should link to children" do
|
28
|
+
child1 = SGF::Node.new
|
29
|
+
child2 = SGF::Node.new
|
30
|
+
child3 = SGF::Node.new
|
31
|
+
@node.add_children child1, child2, child3
|
32
|
+
@node.children.should == [child1, child2, child3]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should link to children, who should get new parents" do
|
36
|
+
child1 = SGF::Node.new
|
37
|
+
child2 = SGF::Node.new
|
38
|
+
child3 = SGF::Node.new
|
39
|
+
@node.add_children child1, child2, child3
|
40
|
+
@node.children.each { |child| child.parent.should == @node }
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should allow properties to be added to" do
|
44
|
+
@node.add_properties "TC" => "Hello,"
|
45
|
+
@node.add_properties "TC" => " world!"
|
46
|
+
@node.properties["TC"].should == "Hello, world!"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should give you the properties based on method given" do
|
50
|
+
@node.add_properties "PW" => "The Tick"
|
51
|
+
@node.add_properties "PB" => "Batmanuel"
|
52
|
+
@node.pw.should == "The Tick"
|
53
|
+
@node.pb.should == "Batmanuel"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow you to change a property completely" do
|
57
|
+
@node.add_properties "RE" => "This is made up"
|
58
|
+
@node.properties["RE"] = "This is also made up"
|
59
|
+
@node.re.should == "This is also made up"
|
60
|
+
@node.re = "And that too"
|
61
|
+
@node.re.should == "And that too"
|
62
|
+
end
|
63
|
+
|
34
64
|
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SgfParser::Tree.parse" do
|
4
|
+
|
5
|
+
it "should have FF in the first node" do
|
6
|
+
tree = SGF::Parser.new('spec/data/ff4_ex.sgf').parse
|
7
|
+
tree.root.children[0].properties.keys.should include("FF")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should give an error if FF is missing from the first node" do
|
11
|
+
pending "To be coded later"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse properly the AW property" do
|
15
|
+
sgf = "dd][de][ef]"
|
16
|
+
parser = SGF::Parser.new sgf
|
17
|
+
parser.get_property.should == "[dd][de][ef]"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require '
|
4
|
-
require 'rspec'
|
5
|
-
require 'rspec/autorun'
|
6
|
-
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'sgf'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
|
data/spec/tree_spec.rb
CHANGED
@@ -1,41 +1,29 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "SgfParser::Tree" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
tree
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
tree2_children = []
|
31
|
-
tree.each { |node| tree_children << node }
|
32
|
-
tree2.each { |node| tree2_children << node }
|
33
|
-
tree_children.size.should == tree2_children.size
|
34
|
-
tree_children.each_with_index do |node, index|
|
35
|
-
node.properties.should == tree2_children[index].properties
|
36
|
-
end
|
37
|
-
tree_children.should == tree2_children
|
38
|
-
tree2.should == tree
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SgfParser::Tree" do
|
4
|
+
|
5
|
+
|
6
|
+
it "should load a file properly" do
|
7
|
+
tree = SGF::Parser.new('spec/data/ff4_ex.sgf').parse
|
8
|
+
tree.class.should == SGF::Tree
|
9
|
+
tree.root.children.size.should == 2
|
10
|
+
tree.root.children[0].children.size.should == 5
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should save a simple tree properly" do
|
14
|
+
tree = SGF::Parser.new('spec/data/simple.sgf').parse
|
15
|
+
new_file = 'spec/data/simple_saved.sgf'
|
16
|
+
tree.save :filename => new_file
|
17
|
+
tree2 = SGF::Parser.new(new_file).parse
|
18
|
+
tree.should == tree2
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should save the sample SGF properly" do
|
22
|
+
tree = SGF::Parser.new('spec/data/ff4_ex.sgf').parse
|
23
|
+
new_file = 'spec/data/ff4_ex_saved.sgf'
|
24
|
+
tree.save :filename => new_file
|
25
|
+
tree2 = SGF::Parser.new(new_file).parse
|
26
|
+
tree2.should == tree
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
CHANGED
@@ -1,77 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: SgfParser
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 1
|
10
|
-
version: 0.9.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Aldric Giacomoni
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-07-29 00:00:00 -04:00
|
12
|
+
date: 2011-08-01 00:00:00.000000000 -04:00
|
19
13
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
type: :development
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
32
16
|
name: jeweler
|
33
|
-
|
34
|
-
prerelease: false
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
type: :development
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &76820790 !ruby/object:Gem::Requirement
|
38
18
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *76820790
|
26
|
+
- !ruby/object:Gem::Dependency
|
46
27
|
name: rcov
|
47
|
-
|
28
|
+
requirement: &76820540 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
48
35
|
prerelease: false
|
49
|
-
|
36
|
+
version_requirements: *76820540
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rdoc
|
39
|
+
requirement: &76820300 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
50
45
|
type: :development
|
51
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *76820300
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: &76820030 !ruby/object:Gem::Requirement
|
52
51
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
hash: 13
|
57
|
-
segments:
|
58
|
-
- 1
|
59
|
-
- 2
|
60
|
-
- 9
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
61
55
|
version: 1.2.9
|
62
|
-
|
63
|
-
version_requirements: *id003
|
56
|
+
type: :development
|
64
57
|
prerelease: false
|
65
|
-
|
58
|
+
version_requirements: *76820030
|
59
|
+
description: SGFParser is a library that parses and saves SGF (Smart Game Format)
|
60
|
+
files.
|
66
61
|
email: aldric@trevoke.net
|
67
62
|
executables: []
|
68
|
-
|
69
63
|
extensions: []
|
70
|
-
|
71
|
-
extra_rdoc_files:
|
64
|
+
extra_rdoc_files:
|
72
65
|
- LICENSE
|
73
66
|
- README.rdoc
|
74
|
-
files:
|
67
|
+
files:
|
75
68
|
- .document
|
76
69
|
- .rspec
|
77
70
|
- .rvmrc
|
@@ -82,56 +75,45 @@ files:
|
|
82
75
|
- Rakefile
|
83
76
|
- SgfParser.gemspec
|
84
77
|
- VERSION
|
85
|
-
- lib/sgf
|
86
|
-
- lib/sgf/
|
87
|
-
- lib/sgf/
|
88
|
-
- lib/sgf/parser
|
89
|
-
- lib/sgf/
|
90
|
-
- lib/sgf/
|
91
|
-
- lib/sgf_parser.rb
|
92
|
-
- sample_sgf/ff4_ex.sgf
|
93
|
-
- sample_sgf/ff4_ex_saved.sgf
|
94
|
-
- sample_sgf/redrose-tartrate.sgf
|
95
|
-
- sample_sgf/simple.sgf
|
96
|
-
- sample_sgf/simple_saved.sgf
|
78
|
+
- lib/sgf.rb
|
79
|
+
- lib/sgf/indenter.rb
|
80
|
+
- lib/sgf/node.rb
|
81
|
+
- lib/sgf/parser.rb
|
82
|
+
- lib/sgf/properties.rb
|
83
|
+
- lib/sgf/tree.rb
|
97
84
|
- sample_usage/parsing_files.rb
|
85
|
+
- spec/data/ff4_ex.sgf
|
86
|
+
- spec/data/ff4_ex_saved.sgf
|
87
|
+
- spec/data/redrose-tartrate.sgf
|
88
|
+
- spec/data/simple.sgf
|
89
|
+
- spec/data/simple_saved.sgf
|
98
90
|
- spec/node_spec.rb
|
91
|
+
- spec/parser_spec.rb
|
99
92
|
- spec/spec_helper.rb
|
100
|
-
- spec/tree_parser_spec.rb
|
101
93
|
- spec/tree_spec.rb
|
102
94
|
has_rdoc: true
|
103
95
|
homepage: http://github.com/Trevoke/SGFParser
|
104
96
|
licenses: []
|
105
|
-
|
106
97
|
post_install_message:
|
107
98
|
rdoc_options: []
|
108
|
-
|
109
|
-
require_paths:
|
99
|
+
require_paths:
|
110
100
|
- lib
|
111
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
102
|
none: false
|
113
|
-
requirements:
|
114
|
-
- -
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
|
117
|
-
|
118
|
-
- 0
|
119
|
-
version: "0"
|
120
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
108
|
none: false
|
122
|
-
requirements:
|
123
|
-
- -
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
|
126
|
-
segments:
|
127
|
-
- 0
|
128
|
-
version: "0"
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
129
113
|
requirements: []
|
130
|
-
|
131
114
|
rubyforge_project:
|
132
115
|
rubygems_version: 1.6.2
|
133
116
|
signing_key:
|
134
117
|
specification_version: 3
|
135
118
|
summary: A library for working with SGF files.
|
136
119
|
test_files: []
|
137
|
-
|
data/lib/sgf/sgfindent.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
module SgfParser
|
2
|
-
|
3
|
-
# This indents an SGF file to make it more readable. It outputs to the screen
|
4
|
-
# by default, but can be given a file as output.
|
5
|
-
# Usage: SgfParser::Indenter.new infile, outfile
|
6
|
-
class Indenter
|
7
|
-
|
8
|
-
def initialize file, out=$stdout
|
9
|
-
sgf = ""
|
10
|
-
File.open(file) { |f| sgf = f.read }
|
11
|
-
@new_string = ""
|
12
|
-
sgf.gsub! "\\\\n\\\\r", ""
|
13
|
-
sgf.gsub! "\\\\r\\\\n", ""
|
14
|
-
sgf.gsub! "\\\\r", ""
|
15
|
-
sgf.gsub! "\\\\n", ""
|
16
|
-
#sgf.gsub! "\n", ""
|
17
|
-
|
18
|
-
end_of_a_series = false
|
19
|
-
identprop = false # We are not in the middle of an identprop value.
|
20
|
-
# An identprop is an identity property - a value.
|
21
|
-
|
22
|
-
sgf_array = sgf.split(//)
|
23
|
-
iterator = 0
|
24
|
-
array_length = sgf_array.size
|
25
|
-
indent = 0
|
26
|
-
|
27
|
-
while iterator < array_length - 1
|
28
|
-
char = sgf_array[iterator]
|
29
|
-
|
30
|
-
case char
|
31
|
-
when '(' # Opening a new branch
|
32
|
-
if !identprop
|
33
|
-
@new_string << "\n"
|
34
|
-
indent += 2
|
35
|
-
#tabulate indent
|
36
|
-
@new_string << " " * indent
|
37
|
-
end
|
38
|
-
@new_string << char
|
39
|
-
|
40
|
-
when ')' # Closing a branch
|
41
|
-
@new_string << char
|
42
|
-
if !identprop
|
43
|
-
@new_string << "\n"
|
44
|
-
indent -= 2
|
45
|
-
@new_string << " " * indent
|
46
|
-
#tabulate indent
|
47
|
-
end
|
48
|
-
|
49
|
-
when ';' # Opening a new node
|
50
|
-
if !identprop
|
51
|
-
@new_string << "\n"
|
52
|
-
@new_string << " " * indent
|
53
|
-
#tabulate indent
|
54
|
-
end
|
55
|
-
@new_string << char
|
56
|
-
|
57
|
-
when '[' # Open comment?
|
58
|
-
if !identprop #If we're not inside a comment, then now we are.
|
59
|
-
identprop = true
|
60
|
-
end_of_a_series = false
|
61
|
-
end
|
62
|
-
@new_string << char
|
63
|
-
|
64
|
-
when ']' # Close comment
|
65
|
-
end_of_a_series = true # Maybe end of a series of comments.
|
66
|
-
identprop = false # That's our cue to close a comment.
|
67
|
-
@new_string << char
|
68
|
-
|
69
|
-
when "\\" # If we're inside a comment, then maybe we're about to escape a ].
|
70
|
-
# This is the whole reason we need this ugly charade of a loop.
|
71
|
-
if identprop
|
72
|
-
if sgf_array[iterator + 1] == "]"
|
73
|
-
@new_string << "\\]"
|
74
|
-
iterator += 1
|
75
|
-
else
|
76
|
-
@new_string << "\\"
|
77
|
-
end
|
78
|
-
else
|
79
|
-
#This should never happen - a backslash outside a comment ?!
|
80
|
-
#But let's not have it be told that I'm not prepared.
|
81
|
-
@new_string << "\\"
|
82
|
-
end
|
83
|
-
|
84
|
-
when "\n"
|
85
|
-
@new_string << "\n"
|
86
|
-
@new_string << " " * indent
|
87
|
-
#tabulate indent
|
88
|
-
|
89
|
-
else
|
90
|
-
# Well, I guess it's "just" a character after all.
|
91
|
-
if end_of_a_series
|
92
|
-
end_of_a_series = false
|
93
|
-
end
|
94
|
-
@new_string << char
|
95
|
-
end
|
96
|
-
|
97
|
-
iterator += 1
|
98
|
-
end
|
99
|
-
|
100
|
-
if out == $stdout
|
101
|
-
$stdout << @new_string
|
102
|
-
else
|
103
|
-
File.open(out, 'w') { |file| file << @new_string }
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
def tabulate indent
|
111
|
-
indent.times { print " " }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|