Module: Bparity::Formal::LtsEncoding

Defined in:
lib/bparity/formal/lts.rb

Class Method Summary collapse

Class Method Details

.normalize(value) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/bparity/formal/lts.rb', line 18

def normalize(value)
  case value
  when Hash
    value.compact.sort_by { |key, _item| key.to_s }
         .to_h { |key, item| [key.to_s, normalize(item)] }
  when Array then value.map { |item| normalize(item) }
  else value
  end
end

.output(outcome) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/bparity/formal/lts.rb', line 10

def output(outcome)
  if outcome.is_a?(Hash) && outcome["kind"] == "raise"
    return "!#{outcome['class']}:#{JSON.generate(normalize(outcome.except('kind', 'class')))}"
  end

  JSON.generate(normalize(outcome))
end