Class: Stupidedi::Schema::Auditor
- Includes:
- Builder::Tokenization, Color
- Defined in:
- lib/stupidedi/schema/auditor.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Class Method Summary collapse
Instance Method Summary collapse
-
#audit ⇒ Object
Throw an exception if the transaction set definition has any ambiguity that could cause non-deterministic parser state.
-
#initialize(machine, reader, isa_elements, gs_elements, st_elements) ⇒ Auditor
constructor
A new instance of Auditor.
Methods included from Builder::Tokenization
#blank, #composite, #default, #not_used, #repeated
Methods included from Color
Constructor Details
#initialize(machine, reader, isa_elements, gs_elements, st_elements) ⇒ Auditor
Returns a new instance of Auditor.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/stupidedi/schema/auditor.rb', line 17 def initialize(machine, reader, isa_elements, gs_elements, st_elements) @config = machine.config @reader = reader @queue = [] @queued = Set.new @elements = Hash.new{|h,k| h[k] = [] } @elements[:ISA] = isa_elements @elements[:GS] = gs_elements @elements[:ST] = st_elements enqueue(machine.active.head) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/stupidedi/schema/auditor.rb', line 12 def config @config end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
13 14 15 |
# File 'lib/stupidedi/schema/auditor.rb', line 13 def machine @machine end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
15 16 17 |
# File 'lib/stupidedi/schema/auditor.rb', line 15 def queue @queue end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
14 15 16 |
# File 'lib/stupidedi/schema/auditor.rb', line 14 def reader @reader end |
Class Method Details
.build(definition) ⇒ Object
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/stupidedi/schema/auditor.rb', line 372 def build(definition) # Use dummy identifiers to link definition to the parser config = mkconfig(definition, "ISA11", "GS01", "GS08", "ST01") builder = Builder::BuilderDsl.new( Builder::StateMachine.build(config, Zipper::Stack), false) # These lists of elements are re-used when Auditor needs to construct # an ISA, GS, or ST segment as it walks the definition. isa_elements = [ "00", "AUTHORIZATION", "00", "PASSWORD", "ZZ", "SUBMITTER ID", "ZZ", "RECEIVER ID", "191225", "1230", "^", "ISA11", "123456789", "0", "T", ":" ] gs_elements = [ "GS01", "SENDER ID", "RECEIVER ID", "20191225", "1230", "1", "X", "GS08" ] st_elements = [ "ST01", "1234" ] builder.ISA(*isa_elements) builder.GS(*gs_elements) builder.ST(*st_elements) new(builder.machine, builder.reader, isa_elements, gs_elements, st_elements) end |
.mkconfig(definition, isa11, gs01, gs08, st01) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/stupidedi/schema/auditor.rb', line 408 def mkconfig(definition, isa11, gs01, gs08, st01) segment = definition.table_defs.head.header_segment_uses.head.definition # Infer the FunctionalGroupDef based on the given `definition` element = segment.element_uses.head.definition version = element.class.name.split('::').slice(0..-3) grpdefn = Object.const_get("FunctionalGroupDef".snoc(version).join('::')) Config.new.customize do |c| c.interchange.customize do |x| # We can use whatever interchange version we like, it does not # have any bearing or relationship to the given `definition` x.register(isa11, Versions::Interchanges::FiveOhOne::InterchangeDef) end c.functional_group.customize do |x| x.register(gs08, grpdefn) end c.transaction_set.customize do |x| x.register(gs08, gs01, st01, definition) end end end |
Instance Method Details
#audit ⇒ Object
Throw an exception if the transaction set definition has any ambiguity that could cause non-deterministic parser state.
33 34 35 36 37 |
# File 'lib/stupidedi/schema/auditor.rb', line 33 def audit while cursor = @queue.shift step(Stupidedi::Builder::StateMachine.new(@config, [cursor])) end end |