Class: SnpVkParser::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/snp_vk_parser/group.rb

Overview

Class for work with group and user in group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Group

Initialize.



10
11
12
# File 'lib/snp_vk_parser/group.rb', line 10

def initialize(params = {})
  params.each { |key, value| instance_variable_set("@#{key}", value) }
end

Instance Attribute Details

#album_idsObject

Returns the value of attribute album_ids.



7
8
9
# File 'lib/snp_vk_parser/group.rb', line 7

def album_ids
  @album_ids
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/snp_vk_parser/group.rb', line 7

def id
  @id
end

#post_idsObject

Returns the value of attribute post_ids.



7
8
9
# File 'lib/snp_vk_parser/group.rb', line 7

def post_ids
  @post_ids
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/snp_vk_parser/group.rb', line 7

def token
  @token
end

#user_idObject

Returns the value of attribute user_id.



7
8
9
# File 'lib/snp_vk_parser/group.rb', line 7

def user_id
  @user_id
end

#vk_clientObject (readonly)

Vk client.



15
16
17
# File 'lib/snp_vk_parser/group.rb', line 15

def vk_client
  @vk_client
end

Instance Method Details

#albums_user_photo_countInteger

Count user photos in albums.

Returns:

  • (Integer)

    Ammount of photos.



58
59
60
61
62
63
64
65
66
# File 'lib/snp_vk_parser/group.rb', line 58

def albums_user_photo_count
  count = 0
  albums.each do |a|
    vk_client.photos.get(owner_id: a.owner_id, album_id: a.aid).each do |p|
      count += 1 if p.user_id == user_id
    end
  end
  count
end

#member?Boolean

Check user is member.

Returns:

  • (Boolean)


70
71
72
# File 'lib/snp_vk_parser/group.rb', line 70

def member?
  vk_client.groups.is_member(group_id: id.abs, user_id: user_id) == 1
end

#membersArray

Members ids.

Returns:

  • (Array)

    Array of user ids.



76
77
78
# File 'lib/snp_vk_parser/group.rb', line 76

def members
  vk_client.groups.get_members(group_id: id.abs).users
end

#posts_user_comment_countInteger

Count user comments in posts.

Returns:

  • (Integer)

    Ammount of comments.



21
22
23
24
25
26
27
28
29
30
# File 'lib/snp_vk_parser/group.rb', line 21

def posts_user_comment_count
  count = 0
  posts.map do |p|
    vk_client.wall.get_comments(owner_id: id, post_id: p.id).each_with_index do |comment, index|
      next if index == 0
      count += 1 if comment.from_id == user_id
    end
  end
  count
end

#posts_user_like_countInteger

Count user likes in posts.

Returns:

  • (Integer)

    Ammount of likes.



34
35
36
37
38
39
40
41
42
# File 'lib/snp_vk_parser/group.rb', line 34

def posts_user_like_count
  count = 0
  posts.map do |p|
    vk_client.likes.get_list(owner_id: id, type: 'post', item_id: p.id).users.each do |u|
      count += 1 if u == user_id
    end
  end
  count
end

#posts_user_repost_countInteger

Count user reposts in posts.

Returns:

  • (Integer)

    Ammount of reposts.



46
47
48
49
50
51
52
53
54
# File 'lib/snp_vk_parser/group.rb', line 46

def posts_user_repost_count
  count = 0
  posts.map do |p|
    vk_client.wall.get_reposts(owner_id: id, post_id: p.id).profiles.each do |u|
      count += 1 if u.uid == user_id
    end
  end
  count
end