Class: Vk::Post

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

Defined Under Namespace

Classes: Wall

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#fields, #id=, #identity_map, inherited, #initialize, #inspect, #key_field, #loader, #logger, method_missing, #method_missing, #read_attribute, #respond_to_missing?, #to_hash

Constructor Details

This class inherits a constructor from Vk::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vk::Base

Class Method Details

.find(*ids) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vk/post.rb', line 11

def find(*ids)
  options = ids.extract_options!
  if ids.count == 1
    id = ids.first
    identity_map[id] ||= new(id, options)
  else
    loaded_ids = ids & identity_map.keys
    ids_to_load = ids - loaded_ids
    identity_map.values_at(*loaded_ids).tap do |result|
      if ids_to_load.any?
        result << loader.get_wall_statuses(ids_to_load).map do |post|
          new(id_for(post), data: post)
        end
      end
    end
  end
end

.id_for(post) ⇒ Object



29
30
31
# File 'lib/vk/post.rb', line 29

def id_for(post)
  "#{post['to_id']}_#{post['id']}"
end

Instance Method Details

#comments_countObject



62
63
64
# File 'lib/vk/post.rb', line 62

def comments_count
  read_attribute(:comments)['count']
end

#copy_ownerObject



54
55
56
# File 'lib/vk/post.rb', line 54

def copy_owner
  @copy_owner ||= Vk::User.find(read_attribute(:copy_owner_id))
end

#copy_postObject



58
59
60
# File 'lib/vk/post.rb', line 58

def copy_post
  @copy_post ||= Vk::Post.find(read_attribute(:copy_owner_id))
end

#dateObject



50
51
52
# File 'lib/vk/post.rb', line 50

def date
  @date ||= Time.at(read_attribute(:date))
end

#fromObject



46
47
48
# File 'lib/vk/post.rb', line 46

def from
  @from ||= Vk::User.find(read_attribute(:from_id))
end

#idObject



34
35
36
# File 'lib/vk/post.rb', line 34

def id
  @attributes[key_field]
end

#likes_countObject



66
67
68
# File 'lib/vk/post.rb', line 66

def likes_count
  read_attribute(:likes)['count']
end

#post_idObject



38
39
40
# File 'lib/vk/post.rb', line 38

def post_id
  @post_id ||= "#{to_id}_#{id}"
end

#toObject



42
43
44
# File 'lib/vk/post.rb', line 42

def to
  @to ||= Vk::User.find(read_attribute(:to_id))
end

#to_sObject



70
71
72
# File 'lib/vk/post.rb', line 70

def to_s
  text
end