class RecordxParser
Public Class Methods
new(s) { |x| ... }
click to toggle source
# File lib/recordx-parser.rb, line 9 def initialize(s) parse(s){|x| yield(x)} end
Public Instance Methods
to_a()
click to toggle source
# File lib/recordx-parser.rb, line 13 def to_a() @a end
Protected Instance Methods
fetch_node(name)
click to toggle source
# File lib/recordx-parser.rb, line 22 def fetch_node(name) self.slice(((self =~ /<#{name}>/) + name.length + 2) .. \ (self =~ /.(?!.*<\/#{name}>)/m) - 1) if self[/<#{name}>/] end
parse(s)
click to toggle source
# File lib/recordx-parser.rb, line 19 def parse(s) s.instance_eval{ def fetch_node(name) self.slice(((self =~ /<#{name}>/) + name.length + 2) .. \ (self =~ /.(?!.*<\/#{name}>)/m) - 1) if self[/<#{name}>/] end } root_name = s[/<(\w+)/,1] summary = RexleParser.new("<summary>#{s.fetch_node(:summary)}</summary>").to_a raw_records = s.fetch_node(:records) records = nil if raw_records then node_name = raw_records[/<(\w+)/,1] a_records = raw_records.strip.split(/(?=<#{node_name}[^>]*>)/) records = fetch_records(a_records) end [root_name, "", {}, [*summary], ['records', "",{}, *records]] end
Private Instance Methods
fetch_records(a_records) { |x| ... }
click to toggle source
# File lib/recordx-parser.rb, line 46 def fetch_records(a_records) a_records.map {|x| yield(x)} end