Class: NeoScout::Verifier
- Inherits:
-
Object
- Object
- NeoScout::Verifier
- Defined in:
- lib/neoscout/json_schema.rb,
lib/neoscout/model.rb
Overview
TODO indexes TODO edges TODO testing
Direct Known Subclasses
Instance Attribute Summary collapse
-
#allowed_edges ⇒ Object
readonly
Returns the value of attribute allowed_edges.
-
#edge_props ⇒ Object
readonly
Returns the value of attribute edge_props.
-
#node_props ⇒ Object
readonly
Returns the value of attribute node_props.
Instance Method Summary collapse
- #add_valid_edge(edge_type, src_type, dst_type) ⇒ Object
- #add_valid_edge_sets(edge_type, src_types, dst_types) ⇒ Object
- #allowed_edge?(edge_type, src_type, dst_type) ⇒ Boolean
- #checked_edge_type?(node_type) ⇒ Boolean
- #checked_node_type?(node_type) ⇒ Boolean
- #init_from_json(json) ⇒ Object
-
#initialize ⇒ Verifier
constructor
A new instance of Verifier.
- #new_card_constr(args = {}) ⇒ Object
- #new_edge_prop_constr(args = {}) ⇒ Object
- #new_node_prop_constr(args = {}) ⇒ Object
Constructor Details
#initialize ⇒ Verifier
Returns a new instance of Verifier.
103 104 105 106 107 |
# File 'lib/neoscout/model.rb', line 103 def initialize @node_props = HashWithDefault.new { |type| ConstrainedSet.new { |o| o.kind_of? Constraints::PropConstraint } } @edge_props = HashWithDefault.new { |type| ConstrainedSet.new { |o| o.kind_of? Constraints::PropConstraint } } @allowed_edges = HashWithDefault.new_multi_keyed(:edge_type, :src_type) { |v| Set.new } end |
Instance Attribute Details
#allowed_edges ⇒ Object (readonly)
Returns the value of attribute allowed_edges.
101 102 103 |
# File 'lib/neoscout/model.rb', line 101 def allowed_edges @allowed_edges end |
#edge_props ⇒ Object (readonly)
Returns the value of attribute edge_props.
100 101 102 |
# File 'lib/neoscout/model.rb', line 100 def edge_props @edge_props end |
#node_props ⇒ Object (readonly)
Returns the value of attribute node_props.
99 100 101 |
# File 'lib/neoscout/model.rb', line 99 def node_props @node_props end |
Instance Method Details
#add_valid_edge(edge_type, src_type, dst_type) ⇒ Object
121 122 123 |
# File 'lib/neoscout/model.rb', line 121 def add_valid_edge(edge_type, src_type, dst_type) @allowed_edges[edge_type][src_type] << dst_type end |
#add_valid_edge_sets(edge_type, src_types, dst_types) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/neoscout/model.rb', line 125 def add_valid_edge_sets(edge_type, src_types, dst_types) src_types.each do |src_type| dst_types.each do |dst_type| add_valid_edge edge_type, src_type, dst_type end end end |
#allowed_edge?(edge_type, src_type, dst_type) ⇒ Boolean
141 142 143 |
# File 'lib/neoscout/model.rb', line 141 def allowed_edge?(edge_type, src_type, dst_type) allowed_edges[edge_type].empty? || allowed_edges[edge_type][src_type].member?(dst_type) end |
#checked_edge_type?(node_type) ⇒ Boolean
137 138 139 |
# File 'lib/neoscout/model.rb', line 137 def checked_edge_type?(node_type) ! @node_props[node_type].empty? end |
#checked_node_type?(node_type) ⇒ Boolean
133 134 135 |
# File 'lib/neoscout/model.rb', line 133 def checked_node_type?(node_type) ! @node_props[node_type].empty? end |
#init_from_json(json) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/neoscout/json_schema.rb', line 18 def init_from_json(json) JSON.cd(json, %w(nodes)).each_pair do |type_name, type_json| JSON.cd(type_json, %w(properties)).each_pair do |prop_name, prop_json| prop_constr = new_node_prop_constr name: prop_name, opt: !prop_json['relevant'] prop_set = self.node_props[type_name] prop_set << prop_constr end end JSON.cd(json, %w(connections)).each_pair do |type_name, type_json| JSON.cd(type_json, %w(properties)).each_pair do |prop_name, prop_json| prop_constr = new_edge_prop_constr name: prop_name, opt: !prop_json['relevant'] prop_set = self.edge_props[type_name] prop_set << prop_constr end sources_json = if type_json.has_key?('sources') then type_json['sources'] else [] end targets_json = if type_json.has_key?('targets') then type_json['targets'] else [] end add_valid_edge_sets type_name, sources_json, targets_json end end |
#new_card_constr(args = {}) ⇒ Object
117 118 119 |
# File 'lib/neoscout/model.rb', line 117 def new_card_constr(args={}) Constraints::CardConstraint.new args end |
#new_edge_prop_constr(args = {}) ⇒ Object
113 114 115 |
# File 'lib/neoscout/model.rb', line 113 def new_edge_prop_constr(args={}) Constraints::PropConstraint.new args end |
#new_node_prop_constr(args = {}) ⇒ Object
109 110 111 |
# File 'lib/neoscout/model.rb', line 109 def new_node_prop_constr(args={}) Constraints::PropConstraint.new args end |