Class: Vk::Result
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/vk/result.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(method, items_class, options = {}, merged_attributes = {}) ⇒ Result
Returns a new instance of Result.
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/vk/result.rb', line 8
def initialize(method, items_class, options = {}, merged_attributes = {})
@items = []
@amount = 0
@client = options.delete(:client) { Vk.client }
@items_class = items_class
@method = method
@options = options
@options[:offset] ||= 0
@options[:count] ||= 100
@merged_attributes = merged_attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, &block) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/vk/result.rb', line 53
def method_missing(name, *arguments, &block)
if respond_to_missing?(name, false)
@items_class.public_send(name, *arguments, &block)
else
super
end
end
|
Instance Attribute Details
#items ⇒ <Vk::Base>
32
33
34
|
# File 'lib/vk/result.rb', line 32
def items
@items
end
|
Instance Method Details
#all ⇒ <Vk::Base>
45
46
47
48
49
50
51
|
# File 'lib/vk/result.rb', line 45
def all
while amount && count && amount < count
increase_offset!
load_items
end
@items
end
|
#amount ⇒ Fixnum
27
28
29
|
# File 'lib/vk/result.rb', line 27
def amount
@items.size
end
|
#count ⇒ Fixnum
21
22
23
24
|
# File 'lib/vk/result.rb', line 21
def count
load_items unless @count
@count
end
|
#each(&block) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/vk/result.rb', line 34
def each(&block)
@items.each do |item|
yield(item)
end
while amount && count && amount < count
increase_offset!
load_items(&block)
end
end
|
#respond_to_missing?(name, include_all) ⇒ Boolean
63
64
65
|
# File 'lib/vk/result.rb', line 63
def respond_to_missing?(name, include_all)
@items_class.respond_to?(name, include_all)
end
|