Browse files

Tokenizer :scan_keyvalue learns how to deal with scopes.

  • Loading branch information...
1 parent e22817f commit 2b2af4260de1d097a13d2fbcad16c51460109582 @weppos committed Jul 3, 2012
Showing with 11 additions and 21 deletions.
  1. +8 −4 lib/whois/record/scanners/base.rb
  2. +3 −17 lib/whois/record/scanners/whois.rnids.rs.rb
View
12 lib/whois/record/scanners/base.rb
@@ -47,14 +47,18 @@ def parse
@input.skip(/\n/)
end
+ # Scan a key/value pair and stores the result in the current target.
+ # target is the global @ast if no '_section' is set, else '_section' is used.
tokenizer :scan_keyvalue do
if @input.scan(/(.+?):(.*?)\n/)
key, value = @input[1].strip, @input[2].strip
- if @ast[key].nil?
- @ast[key] = value
+ target = @tmp['_section'] ? (@ast[@tmp['_section']] ||= {}) : @ast
+
+ if target[key].nil?
+ target[key] = value
else
- @ast[key] = Array.wrap(@ast[key])
- @ast[key] << value
+ target[key] = Array.wrap(target[key])
+ target[key] << value
end
end
end
View
20 lib/whois/record/scanners/whois.rnids.rs.rb
@@ -23,7 +23,7 @@ class WhoisRnidsRs < Base
:scan_available,
:skip_comment,
:flag_section_start,
- :scan_section_keyvalue,
+ :scan_keyvalue,
:flag_section_end,
:skip_empty_line,
:skip_privacy,
@@ -40,28 +40,14 @@ class WhoisRnidsRs < Base
tokenizer :flag_section_start do
if SECTIONS.any? { |section| @input.check(/^(#{section}):/) }
- @tmp["section"] = @input[1]
+ @tmp['_section'] = @input[1]
end
false
end
tokenizer :flag_section_end do
if @input.match?(/^\n/)
- @tmp.delete("section")
- end
- end
-
- tokenizer :scan_section_keyvalue do
- if @input.scan(/(.+?):(.*?)\n/)
- key, value = @input[1].strip, @input[2].strip
- target = @tmp["section"] ? (@ast[@tmp["section"]] ||= {}) : @ast
-
- if target[key].nil?
- target[key] = value
- else
- target[key] = Array.wrap(target[key])
- target[key] << value
- end
+ @tmp.delete('_section')
end
end

0 comments on commit 2b2af42

Please sign in to comment.