Sha256: d0eed54d0a2802421832dcae10b5abde237497b5d3e75c51f6900b26437b24d6

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

=begin rdoc
  Array extensions
=end
require "enumerator"
class Array
  def to_os
    map {|a| a.to_os }
  end
  
  def collect_with_index &block
    self.enum_for(:each_with_index).collect &block
  end
  
  def runnable(quiet=true)
    self.join(" \n ").runnable(quiet)
  end
  
  def nice_runnable(quiet=true)
    self.flatten.reject{|e| (e.nil? || e.empty?) }.join(" \n ").chomp.nice_runnable(quiet)
  end
  
  def to_string(pre="")
    map {|a| a.to_string(pre)}.join("\n")
  end
  
  def get_named(str="")
    map {|a| a.name == str ? a : nil }.reject {|a| a.nil? }
  end
  
  def respec_string(ns=[])
    "'#{map {|e| e.to_option_string }.join("', '")}'"
  end
  # Example  nodes.select_with_hash(:status=>'running')
  def select_with_hash(conditions={})
    return self if conditions.empty?
    select do |node|
      conditions.any? do |k,v| 
        ( node.has_key?(k) && node[k]==v ) or ( node.respond_to?(k) && node.send(k)==v )
      end
    end
  end
  
  def wrapping_next(id)
    raise "Element #{id} not in array" unless index(id)
    index(id) >= size-1 ? at(0) : at(index(id)+1)
  end
    
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
auser-poolparty-1.1.6 lib/poolparty/core/array.rb
auser-poolparty-1.1.7 lib/poolparty/core/array.rb
auser-poolparty-1.2.0 lib/poolparty/core/array.rb
auser-poolparty-1.2.1 lib/poolparty/core/array.rb
auser-poolparty-1.2.2 lib/poolparty/core/array.rb
auser-poolparty-1.2.3 lib/poolparty/core/array.rb
auser-poolparty-1.2.4 lib/poolparty/core/array.rb
auser-poolparty-1.2.7 lib/poolparty/core/array.rb
auser-poolparty-1.2.8 lib/poolparty/core/array.rb
fairchild-poolparty-1.1.5 lib/poolparty/core/array.rb
poolparty-1.2.2 lib/poolparty/core/array.rb