module Petri::NetLoader::ClassMethods
Public Instance Methods
from_file(path)
click to toggle source
@param path [String] @return [Net]
# File lib/petri/net_loader.rb, line 111 def from_file(path) from_stream(File.new(path)) end
from_hash(hash)
click to toggle source
@param hash [Hash<String>] @return [Net]
# File lib/petri/net_loader.rb, line 129 def from_hash(hash) self.new.tap do |net| hash['places'].each do |data| net.add_place(guid: data['guid'], identifier: data['identifier'], start: data['start'], finish: data['finish']) end hash['transitions'].each do |data| net.add_transition(guid: data['guid'], identifier: data['identifier'], automated: data['automated'], action: data['action']) end hash['messages'].each do |data| net.add_message(guid: data['guid'], identifier: data['identifier']) end if hash['messages'] hash['tasks'].each do |data| net.add_task(data, hash) end if hash['tasks'] hash['arcs'].each do |data| net.add_arc(guid: data['guid'], from_guid: data['from_guid'], to_guid: data['to_guid'], type: data['type'], production_rule: data['production_rule'], timer_rule: data['timer_rule'], guard: data['guard']) end end end
from_stream(io)
click to toggle source
@param io [IO] @return [Net]
# File lib/petri/net_loader.rb, line 117 def from_stream(io) from_string(io.read) end
from_string(str)
click to toggle source
@param str [String] @return [Net]
# File lib/petri/net_loader.rb, line 123 def from_string(str) from_hash(JSON.parse(str)) end