Class: Gotasku::Parser

Inherits:
SGF::Parser
  • Object
show all
Defined in:
lib/gotasku/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(sgf) ⇒ Object

validates and parses sgf string



4
5
6
# File 'lib/gotasku/parser.rb', line 4

def parse(sgf)
   super(validate(sgf))	
end

#validate(sgf) ⇒ Object

validates sgf string for common goproblems.com issues



9
10
11
# File 'lib/gotasku/parser.rb', line 9

def validate(sgf)
  validate_for(validate_for(sgf, :AB), :AW)
end

#validate_for(sgf, property) ⇒ Object

validates for a property (AB or AW)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gotasku/parser.rb', line 14

def validate_for(sgf, property)
	regs = {AB: /AB/, AW: /AW/}

	# find the first instance, all will be replaced and the first 
	# instance will be readded
	start = sgf =~ regs[property] 

	if start
		sgf.gsub!(regs[property], '')
		sgf = sgf[0...start] + property.to_s + sgf[start..-1]
	end

	sgf
end