Sha256: cf7d258bd4ea371fcb2eb794cf6e648a02394b223671b0ea71df7cb983fbc620

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module BOSDK
  # Creates a wrapper around an IInfoObject.
  class InfoObject
    # The underlying IInfoObject.
    attr_reader :obj

    # Creates a new InfoObject from the provided IInfoObject.
    #  InfoObject.new(obj)
    def initialize(obj)
      @obj = obj
    end

    # Returns true/false if #obj is a root node.
    def is_root?
      parent_id.nil? or parent_id == 0 or parent_id == getID
    end

    # Returns the parent of #obj as an InfoObject
    def parent
      return nil if is_root?
      @parent ||= InfoObject.new(getParent)
    end

    # Returns the path of #obj as a String.
    def path
      @path ||= (is_root? ? '' : parent.path) + "/#{title}"
    end

    # Compares one InfoObject to another by #title.
    def <=>(other_infoobject)
      title <=> other_infoobject.title
    end

    # Forwards method to underlying IInfoObject and stores the results
    def method_missing(method, *args)
      eval "return @#{method.to_s}" if instance_variables.include?("@#{method.to_s}")
      if @obj.respond_to?(method)
        eval "return @#{method.to_s} = @obj.send(method, *args)"
      end
      super
    end

    # Returns true if underlying IInfoObject#respond_to? is true
    def respond_to?(method)
      @obj.respond_to?(method) || super
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bosdk-1.0.3-universal-java-1.6 lib/bosdk/info_object.rb
bosdk-1.0.2-universal-java-1.6 lib/bosdk/info_object.rb
bosdk-1.0.1-universal-java-1.6 lib/bosdk/info_object.rb
bosdk-1.0.0-universal-java-1.6 lib/bosdk/info_object.rb