Module: Ea::Transformers::QeaToXmi::RunState

Defined in:
lib/ea/transformers/qea_to_xmi/run_state.rb

Overview

Pure-function parser for EA's RunState column on t_object.

EA serialises instance-specification run-state as a delimited string of the form:

@VAR;Variable=<name>;Value=<value>;Op=<op>;@ENDVAR;

Multiple variables concatenate directly:

@VAR;Variable=a;Value=1;Op==;@ENDVAR;@VAR;Variable=b;Value=2;Op==;@ENDVAR;

Each @VAR ... @ENDVAR; block maps to one UML Slot. The Variable is the attribute name on the classifier (used to resolve the definingFeature EAID at transformation time). The Value plus Op form the OpaqueExpression body — Sparx prepends the operator character to the value (Op==body="=Value").

The parser is pure: no I/O, no state. Same input always yields the same output array of Value, Op structs.

Defined Under Namespace

Classes: Binding

Class Method Summary collapse

Class Method Details

.each_var_block(raw) ⇒ Object

Yields each @VAR;...;@ENDVAR; block body (without the delimiters). Tolerant of multiple blocks concatenated without separation.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ea/transformers/qea_to_xmi/run_state.rb', line 66

def each_var_block(raw)
  return enum_for(:each_var_block, raw) unless block_given?

  scanner = StringScanner.new(raw)
  until scanner.eos?
    scanner.scan_until(/@VAR;/) || break
    body = scanner.scan_until(/@ENDVAR;/)
    break if body.nil?

    yield body.sub(/@ENDVAR;\z/, "")
  end
end

.parse(raw) ⇒ Array<Binding>

Returns one Binding per @VAR block; empty array for nil/empty/blank input.

Parameters:

  • raw (String, nil)

    the EA RunState column content

Returns:

  • (Array<Binding>)

    one Binding per @VAR block; empty array for nil/empty/blank input.



52
53
54
55
56
57
58
59
# File 'lib/ea/transformers/qea_to_xmi/run_state.rb', line 52

def parse(raw)
  return [] if raw.nil? || raw.to_s.strip.empty?

  stripped = raw.to_s
  each_var_block(stripped).map do |block|
    parse_binding(block)
  end
end

.parse_binding(block) ⇒ Binding

Parameters:

  • block (String)

    the inside of one @VAR;...;@ENDVAR; block, e.g. Variable=a;Value=1;Op==;

Returns:



82
83
84
85
86
87
88
89
# File 'lib/ea/transformers/qea_to_xmi/run_state.rb', line 82

def parse_binding(block)
  fields = parse_fields(block)
  Binding.new(
    fields["Variable"] || "",
    fields["Value"] || "",
    fields["Op"] || "",
  )
end

.parse_fields(block) ⇒ Hash{String=>String}

Parse Key=value; pairs into a Hash. Values may contain ; literally — only split on ; immediately followed by a known key boundary. In practice EA's values rarely contain semicolons, so a simple split is sufficient.

Parameters:

  • block (String)

Returns:

  • (Hash{String=>String})


98
99
100
101
102
103
# File 'lib/ea/transformers/qea_to_xmi/run_state.rb', line 98

def parse_fields(block)
  block.split(";").each_with_object({}) do |pair, hash|
    key, value = pair.split("=", 2)
    hash[key] = value.to_s if key && !key.empty?
  end
end