module Ooz module Model class Ooze < Base::Ooze overridable_const :evolution_class, Model::Evolution overridable_const :section_class, Model::Section overridable_const :field_factory_class, Model::FieldFactory overridable_const :force_class, Model::Force def tagged?(tag, search_on: :tags) haystack = self.send(search_on) haystack.include?(tag) end def stages? evolution && evolution.stages&.length > 0 end def stages return [] if !stages? evolution.stages end def stages_hash to_hash(stages) end def stages_by_section stages.map do |stg| stg.flow_node_ids.map do |id| [id, stg] end end.flatten(1).group_by do |pair| pair.first end.transform_values do |arr_pairs| arr_pairs.map {|pair| pair.last} end end def fields membranes end def fields_hash(key: "_id", silent: true) fields.group_by do |fld| fld.send(key) end.transform_values do |flds| if flds.length == 1 flds.first else master = flds.first next master unless master.is_a?(Ooz::Model::Field::Select) rest = flds[1..-1] rest.each do |fld| if fld.is_a?(Ooz::Model::Field::Select) master.other ||= fld.other master.multiple ||= fld.multiple Ooz::Base::Field::Select.merge_options(master, fld, silent: silent) end end master end end end def sections flow_nodes end def sections_hash to_hash(sections) end def sections_by_field sections.map do |sec| sec.field_ids.map do |id| [id, sec] end end.flatten(1).to_h end def bindings forces.reduce([]) do |binds, f| binds + f.bindings end end def bindings_by_field bindings.group_by do |b| b.reference_id end end end end end