Class: Ygg::DataBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/ygg/databundle.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_array = nil) ⇒ DataBundle

Returns a new instance of DataBundle.



3
4
5
# File 'lib/ygg/databundle.rb', line 3

def initialize(source_array = nil)
  @data = source_array || []
end

Instance Method Details

#<<(*args) ⇒ Object



18
# File 'lib/ygg/databundle.rb', line 18

def <<(*args); @data.<<(*args); end

#each(&block) ⇒ Object



21
# File 'lib/ygg/databundle.rb', line 21

def each(&block); @data.each { |e| block.call(e) }; end

#empty?Boolean

Returns:

  • (Boolean)


17
# File 'lib/ygg/databundle.rb', line 17

def empty?; @data.empty?; end

#firstObject

Delegate to array



16
# File 'lib/ygg/databundle.rb', line 16

def first; @data.first; end

#include?(*args) ⇒ Boolean

Returns:

  • (Boolean)


20
# File 'lib/ygg/databundle.rb', line 20

def include?(*args); @data.include?(*args); end

#lastObject



23
# File 'lib/ygg/databundle.rb', line 23

def last; @data.last; end

#lengthObject



22
# File 'lib/ygg/databundle.rb', line 22

def length; @data.length; end

#of_type(type) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/ygg/databundle.rb', line 7

def of_type(type)
  @result = DataBundle.new
  @data.each do |resource|
    @result << resource if resource.instance_of? type
  end
  return @result.empty? ? nil : @result
end

#to_yamlObject



19
# File 'lib/ygg/databundle.rb', line 19

def to_yaml; @data.to_yaml; end