Sha256: 9f9ddf99be3030d4f55b800a3545fae15a46260de3e11c116ddbbd929020da9a

Contents?: true

Size: 658 Bytes

Versions: 10

Compression:

Stored size: 658 Bytes

Contents

module FlexmlsApi
  class PrimaryArray < Array
    
    def primary
      find_primary
    end

    private 
    
    # This is a very simplistic but reliable implementation.
    def find_primary
      self.each do |arg|
        if arg.primary?
          return arg
        end
      end
      nil
    end
  end
  
  #=== Primary: interface to implement for elements that are added to a "PrimaryArray" collection
  module Primary
    # Return true if the element is the primary resource in a collection.
    # Default implementation looks for a "Primary" attribute
    def primary?
      @attributes.key?("Primary") && self.Primary == true
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
spark_api-1.0.2 lib/spark_api/primary_array.rb~
spark_api-1.0.1 lib/spark_api/primary_array.rb~
spark_api-1.0.0 lib/spark_api/primary_array.rb~
flexmls_api-0.7.3 lib/flexmls_api/primary_array.rb
flexmls_api-0.7.5 lib/flexmls_api/primary_array.rb
flexmls_api-0.7.0 lib/flexmls_api/primary_array.rb
flexmls_api-0.6.5 lib/flexmls_api/primary_array.rb
flexmls_api-0.6.4 lib/flexmls_api/primary_array.rb
flexmls_api-0.4.5 lib/flexmls_api/primary_array.rb
flexmls_api-0.3.6 lib/flexmls_api/primary_array.rb