Class: Stupidedi::Builder::FunctionalGroupState

Inherits:
AbstractState show all
Defined in:
lib/stupidedi/builder/states/functional_group_state.rb

Instance Attribute Summary collapse

Constructors collapse

Instance Method Summary collapse

Methods inherited from AbstractState

#leaf?, lsequence, mkcomposite, mkelement, mkrepeated, mksegment, mksimple, #pretty_print, sequence, tsequence

Methods included from Inspect

#inspect

Constructor Details

#initialize(separators, segment_dict, instructions, zipper, children, fgcode, version) ⇒ FunctionalGroupState

Returns a new instance of FunctionalGroupState



30
31
32
33
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 30

def initialize(separators, segment_dict, instructions, zipper, children, fgcode, version)
  @separators, @segment_dict, @instructions, @zipper, @children, @fgcode, @version =
    separators, segment_dict, instructions, zipper, children, fgcode, version
end

Instance Attribute Details

#childrenArray<AbstractState> (readonly)

Returns:



22
23
24
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 22

def children
  @children
end

#fgcodeString (readonly)

Returns:

  • (String)


25
26
27
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 25

def fgcode
  @fgcode
end

#instructionsInstructionTable (readonly)

Returns:



16
17
18
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 16

def instructions
  @instructions
end

#segment_dictReader::SegmentDict (readonly)

Returns:



13
14
15
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 13

def segment_dict
  @segment_dict
end

#separatorsReader::Separators (readonly)

Returns:



10
11
12
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 10

def separators
  @separators
end

#versionString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 28

def version
  @version
end

#zipperZipper::AbstractCursor (readonly)



19
20
21
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 19

def zipper
  @zipper
end

Class Method Details

.push(zipper, parent, segment_tok, segment_use, config) ⇒ Zipper::AbstractCursor



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 53

def push(zipper, parent, segment_tok, segment_use, config)
  # GS08: Version / Release / Industry Identifier Code
  version = segment_tok.element_toks.at(7).try(:value)
  gscode  = version.try(:slice, 0, 6)

  # GS01: Functional Identifier Code
  fgcode = segment_tok.element_toks.at(0).try(:value)

  unless config.functional_group.defined_at?(gscode)
    return FailureState.push(
      zipper,
      parent,
      segment_tok,
      "unknown functional group version #{gscode.inspect}")
  end

  envelope_def = config.functional_group.at(gscode)
  envelope_val = envelope_def.empty
  segment_use  = envelope_def.entry_segment_use
  segment_val  = mksegment(segment_tok, segment_use)

  zipper.append_child new(
    parent.separators,
    parent.segment_dict.push(envelope_val.segment_dict),
    parent.instructions.push(instructions(envelope_def)),
    parent.zipper.append(envelope_val).append_child(segment_val),
    [], fgcode, version)
end

Instance Method Details

#copy(changes = {}) ⇒ FunctionalGroupState



36
37
38
39
40
41
42
43
44
45
# File 'lib/stupidedi/builder/states/functional_group_state.rb', line 36

def copy(changes = {})
  FunctionalGroupState.new \
    changes.fetch(:separators, @separators),
    changes.fetch(:segment_dict, @segment_dict),
    changes.fetch(:instructions, @instructions),
    changes.fetch(:zipper, @zipper),
    changes.fetch(:children, @children),
    changes.fetch(:fgcode, @fgcode),
    changes.fetch(:version, @version)
end