Sha256: de13d2d710e09eb35454d3d4544455ac93fae42acd350b2eec45f6cb6ff81ae5

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

module Expressir
  module Model
    class Function
      attr_accessor :id
      attr_accessor :parameters
      attr_accessor :return_type
      attr_accessor :declarations
      attr_accessor :constants
      attr_accessor :variables
      attr_accessor :statements

      attr_accessor :parent
      attr_accessor :remarks

      def initialize(options = {})
        @id = options[:id]
        @parameters = options[:parameters]
        @return_type = options[:return_type]
        @declarations = options[:declarations]
        @constants = options[:constants]
        @variables = options[:variables]
        @statements = options[:statements]
      end

      def types
        @declarations.select{|x| x.instance_of? Expressir::Model::Type}
      end

      def entities
        @declarations.select{|x| x.instance_of? Expressir::Model::Entity}
      end

      def subtype_constraints
        @declarations.select{|x| x.instance_of? Expressir::Model::SubtypeConstraint}
      end

      def functions
        @declarations.select{|x| x.instance_of? Expressir::Model::Function}
      end

      def procedures
        @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
      end

      def children
        items = []
        items.push(*@parameters) if @parameters
        items.push(*@declarations.flat_map do |x|
          [
            x,
            *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
              x.type.items
            end
          ]
        end) if @declarations
        items.push(*@constants) if @constants
        items.push(*@variables) if @variables
        items
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
expressir-0.2.3 lib/expressir/model/function.rb