Class: Wizypay::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wizypay/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, data, meta = {}) ⇒ Collection

Returns a new instance of Collection.



4
5
6
7
# File 'lib/wizypay/collection.rb', line 4

def initialize(klass, data, meta = {})
  @data = data.map {|h| klass.new(h)}
  @meta = meta || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/wizypay/collection.rb', line 13

def method_missing(m, *args, &block)
  if data.respond_to?(m)
    data.send(m, *args, &block)
  elsif meta.has_key?(m.to_s)
    meta[m.to_s]
  else
    super
  end
end

Instance Method Details

#respond_to?(m) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/wizypay/collection.rb', line 9

def respond_to?(m)
  data.respond_to?(m) || meta.has_key?(m.to_s) || super
end