Sha256: a4b7981278ebe688bf73c348b3e7c20593c864824e642c57fca5c4c5089a782d

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

module Expressir
  module Model
    module Scope
      def find(path)
        current_path, _, rest = path.partition(".")

        # ignore prefix
        _, _, current_path = current_path.rpartition(":")

        current_path = current_path.downcase
        child = children.find{|x| x.id and x.id.downcase == current_path}

        if !rest.empty? and child.class.method_defined? :find
          child.find(rest)
        else
          child
        end
      end

      def find_or_create(path)
        child = find(path)

        if !child
          # check if path should create implicit informal proposal
          # see https://github.com/lutaml/expressir/issues/50
          rest, _, current_path = path.rpartition(".")

          if !rest.empty?
            child = find(rest)
          else
            child = self
          end

          if child.class.method_defined? :informal_propositions
            # ignore prefix
            _, _, current_path = current_path.rpartition(":")

            # match informal proposition id
            informal_proposition_id = current_path.match(/^IP\d+$/).to_a[0]

            if informal_proposition_id
              # create implicit informal proposition
              informal_proposition = Model::InformalProposition.new({
                id: informal_proposition_id
              })
              informal_proposition.parent = child

              child.informal_propositions << informal_proposition

              informal_proposition
            end
          end
        else
          child
        end
      end

      def children
        raise 'Not implemented'
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
expressir-0.2.10 lib/expressir/model/scope.rb
expressir-0.2.10-x86_64-linux lib/expressir/model/scope.rb
expressir-0.2.10-x86_64-darwin lib/expressir/model/scope.rb
expressir-0.2.10-x86-mingw32 lib/expressir/model/scope.rb
expressir-0.2.10-x86-linux lib/expressir/model/scope.rb
expressir-0.2.10-x64-mingw32 lib/expressir/model/scope.rb
expressir-0.2.10-arm64-darwin lib/expressir/model/scope.rb