Class: Array

Inherits:
Object show all
Defined in:
lib/poolparty/core/array.rb

Direct Known Subclasses

Aska::Rules

Instance Method Summary collapse

Instance Method Details

#collect_with_index(&block) ⇒ Object



10
11
12
# File 'lib/poolparty/core/array.rb', line 10

def collect_with_index &block
  self.enum_for(:each_with_index).collect &block
end

#get_named(str = "") ⇒ Object



26
27
28
# File 'lib/poolparty/core/array.rb', line 26

def get_named(str="")
  map {|a| a.name == str ? a : nil }.reject {|a| a.nil? }
end

#nice_runnable(quiet = true) ⇒ Object



18
19
20
# File 'lib/poolparty/core/array.rb', line 18

def nice_runnable(quiet=true)
  self.flatten.reject{|e| (e.nil? || e.empty?) }.join(" \n ").chomp.nice_runnable(quiet)
end

#respec_string(ns = []) ⇒ Object



30
31
32
# File 'lib/poolparty/core/array.rb', line 30

def respec_string(ns=[])
  "'#{map {|e| e.to_option_string }.join("', '")}'"
end

#runnable(quiet = true) ⇒ Object



14
15
16
# File 'lib/poolparty/core/array.rb', line 14

def runnable(quiet=true)
  self.join(" \n ").runnable(quiet)
end

#select_with_hash(conditions = {}) ⇒ Object

Example nodes.select_with_hash(:status=>‘running’)



34
35
36
37
38
39
40
41
# File 'lib/poolparty/core/array.rb', line 34

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

#to_osObject



6
7
8
# File 'lib/poolparty/core/array.rb', line 6

def to_os
  map {|a| a.to_os }
end

#to_string(pre = "") ⇒ Object



22
23
24
# File 'lib/poolparty/core/array.rb', line 22

def to_string(pre="")
  map {|a| a.to_string(pre)}.join("\n")
end

#wrapping_next(id) ⇒ Object



43
44
45
46
# File 'lib/poolparty/core/array.rb', line 43

def wrapping_next(id)
  raise "Element #{id} not in array" unless index(id)
  index(id) >= size-1 ? at(0) : at(index(id)+1)
end