Class: DynarexParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dynarex-parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ DynarexParser

Returns a new instance of DynarexParser.



9
10
11
12
13
14
15
16
17
18
# File 'lib/dynarex-parser.rb', line 9

def initialize(s)
      
  schema = s[/schema>([^<]+)/,1]
  record_name, raw_fields = schema.match(/(\w+)\(([^\(]+)\)$/).captures
  
  error_found = raw_fields.split(',').include? record_name
  raise "record name must not match a field name" if error_found
  
  @a = parse(s.split(/(?=<!--)/).map {|x| x.sub(/<!--.*-->/m,'')}.join)
end

Instance Method Details

#to_aObject



20
21
22
# File 'lib/dynarex-parser.rb', line 20

def to_a()
  @a
end