Sha256: 90f3c676031515d01a72c4d0d91e35d864f6eab037ec24970a3b71d9a5e93b3d

Contents?: true

Size: 1.82 KB

Versions: 135

Compression:

Stored size: 1.82 KB

Contents

module Expressir
  module Express
    class Derived < ExplicitOrDerived
      attr_accessor :expression

      def initialize(options = {})
        @options = options
        @entity = options.fetch(:entity, nil)
      end

      def parse
        document = @options.fetch(:document, nil)
        extract_common_attributes(document)
        extract_type_specific_attributes(document)

        self
      end

      def self.parse(document, entity)
        new(document: document, entity: entity).parse
      end

      private

      def extract_type_specific_attributes(document); end

      def extract_common_attributes(document)
        @name = document.attributes["name"].to_s
        @expression = document.attributes["expression"].to_s
        @domain = extract_domain_name(document.xpath("typename"))

        extract_builtintype_attributes(document)
        extract_redeclaration_attributes(document)
      end

      def extract_domain_name(typename)
        unless typename.empty?
          typename.first.attributes["name"].to_s
        end
      end

      def extract_redeclaration_attributes(document)
        redeclaration = document.xpath("redeclaration").first

        if redeclaration
          @redeclare_entity = redeclaration.attributes["entity-ref"].to_s
          old_name = redeclaration.attributes["old_name"]
          @redeclare_oldname = old_name.to_s if old_name
        end
      end

      def extract_builtintype_attributes(document)
        builtin_type = document.xpath("builtintype").first

        if builtin_type
          @isBuiltin = true
          @domain = builtin_type.attributes["type"].to_s
          @width = builtin_type.attributes["width"].to_s
          @fixed = builtin_type.attributes["fixed"] == "YES"
          @precision = builtin_type.attributes["precision"].to_s
        end
      end
    end
  end
end

Version data entries

135 entries across 135 versions & 1 rubygems

Version Path
expressir-0.2.27 lib/expressir/express/derived.rb
expressir-0.2.27-x86_64-linux lib/expressir/express/derived.rb
expressir-0.2.27-x86_64-darwin lib/expressir/express/derived.rb
expressir-0.2.27-x86-mingw32 lib/expressir/express/derived.rb
expressir-0.2.27-x86-linux lib/expressir/express/derived.rb
expressir-0.2.27-x64-mingw32 lib/expressir/express/derived.rb
expressir-0.2.27-arm64-darwin lib/expressir/express/derived.rb
expressir-0.2.26 lib/expressir/express/derived.rb
expressir-0.2.26-x86_64-linux lib/expressir/express/derived.rb
expressir-0.2.26-x86_64-darwin lib/expressir/express/derived.rb
expressir-0.2.26-x86-mingw32 lib/expressir/express/derived.rb
expressir-0.2.26-x86-linux lib/expressir/express/derived.rb
expressir-0.2.26-x64-mingw32 lib/expressir/express/derived.rb
expressir-0.2.26-arm64-darwin lib/expressir/express/derived.rb
expressir-0.2.25 lib/expressir/express/derived.rb
expressir-0.2.25-x86_64-linux lib/expressir/express/derived.rb
expressir-0.2.25-x86_64-darwin lib/expressir/express/derived.rb
expressir-0.2.25-x86-mingw32 lib/expressir/express/derived.rb
expressir-0.2.25-x86-linux lib/expressir/express/derived.rb
expressir-0.2.25-x64-mingw32 lib/expressir/express/derived.rb