Class: Delphix::BaseArray

Inherits:
Array
  • Object
show all
Defined in:
lib/delphix/base_array.rb

Instance Method Summary collapse

Instance Method Details

#filter_by(key, value) ⇒ Object

Filters an array bases on a key and a value. NOTE: The resulting array is a shallow copy of the original array!



36
37
38
39
40
41
42
43
44
# File 'lib/delphix/base_array.rb', line 36

def filter_by(key, value)
  return nil if self.size == 0
  a = Delphix::BaseArray.new
  self.each do |o|
    a << o if o.details[key] == value
  end
  return nil if a.size == 0
  a
end

#lookup_by_name(name) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/delphix/base_array.rb', line 16

def lookup_by_name(name)
  return nil if self.size == 0
  self.each do |o|
    return o if o.name == name
  end
  return nil
end

#lookup_by_ref(ref) ⇒ Object

lookup_by_ref, lookup_by_name & lookup_by_type assume that there is only one match in the array. In case there are multiple matches, the first one is returned.



8
9
10
11
12
13
14
# File 'lib/delphix/base_array.rb', line 8

def lookup_by_ref(ref)
  return nil if self.size == 0
  self.each do |o|
    return o if o.reference == ref
  end
  return nil
end

#lookup_by_type(type) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/delphix/base_array.rb', line 24

def lookup_by_type(type)
  return nil if self.size == 0
  self.each do |o|
    return o if o.type == type
  end
  return nil
end