Sha256: 2ffe065a108f88b45ba7317f978cd7c242494fb7e7b6bb305cc506a088aa4d68

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

require "uri"

module Resources
  
  class Base < ActiveResource::Base
    
    def self.configure(uri_options)
      uri = URI.parse(uri_options[:url])
      uri.user = uri_options[:username]
      uri.password = uri_options[:password]
      self.site = uri
    end

    def self.print_collection(collection, attributes, align = :left)
      output = []
      longest_attributes = Array.new(attributes.length, 0)
      alignment = (align == :left ? :ljust : :rjust)
      collection.each do |element|
        entry = []
        attributes.each_with_index do |attribute, index|
          attribute_value = element.send(attribute).to_s
          longest_attributes[index] = attribute_value.length if attribute_value.length > longest_attributes[index]
          entry << attribute_value
        end
        output << entry
      end
      output.each do |entry|
        row = []
        entry.each_with_index do |part, index|
          row << [part.send(alignment, longest_attributes[index])]
        end
        puts row.join(" - ")
      end
    end
    
    def self.warn(message)
      puts "Warning: #{message}"
    end
  
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
schubert-minglr-1.2.0 lib/minglr/resources/base.rb
schubert-minglr-1.3.0 lib/minglr/resources/base.rb
schubert-minglr-1.3.1 lib/minglr/resources/base.rb
schubert-minglr-1.3.11 lib/minglr/resources/base.rb
schubert-minglr-1.3.2 lib/minglr/resources/base.rb
schubert-minglr-1.3.3 lib/minglr/resources/base.rb
schubert-minglr-1.3.5 lib/minglr/resources/base.rb
schubert-minglr-1.3.8 lib/minglr/resources/base.rb
schubert-minglr-1.3.9 lib/minglr/resources/base.rb
minglr-1.3.11 lib/minglr/resources/base.rb