Class: Vk::Post::Wall

Inherits:
Object
  • Object
show all
Defined in:
lib/vk/post/wall.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, count, posts) ⇒ Wall

Returns a new instance of Wall.



10
11
12
# File 'lib/vk/post/wall.rb', line 10

def initialize(uid, count, posts)
  self.uid, self.count, self.posts = uid, count, posts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/vk/post/wall.rb', line 34

def method_missing(method, *args)
  if posts.respond_to?(method)
    posts.send(method, *args)
  else
    super
  end
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



8
9
10
# File 'lib/vk/post/wall.rb', line 8

def count
  @count
end

#postsObject

Returns the value of attribute posts.



8
9
10
# File 'lib/vk/post/wall.rb', line 8

def posts
  @posts
end

#uidObject

Returns the value of attribute uid.



8
9
10
# File 'lib/vk/post/wall.rb', line 8

def uid
  @uid
end

Instance Method Details

#[](index) ⇒ Object



18
19
20
21
22
23
# File 'lib/vk/post/wall.rb', line 18

def [](index)
  raise "Post #{index} is not exist"  if index > count + 1
  load_posts_to(index)                if index >= loaded_posts
  post = posts[index]
  Vk::Post.find(Vk::Post.id_for(post), data: post) if post
end

#each(&block) ⇒ Object



27
28
29
30
31
32
# File 'lib/vk/post/wall.rb', line 27

def each(&block)
  load_all_posts
  0.upto(count) do |index|
    block.call(self[index])
  end
end

#firstObject



25
# File 'lib/vk/post/wall.rb', line 25

def first; self[0]; end

#userObject



14
15
16
# File 'lib/vk/post/wall.rb', line 14

def user
  @user ||= Vk::User.find(uid)
end