Class: SnpVkParser::Group
- Inherits:
-
Object
- Object
- SnpVkParser::Group
- Defined in:
- lib/snp_vk_parser/group.rb
Overview
Class for work with group and user in group.
Instance Attribute Summary collapse
-
#album_ids ⇒ Object
Returns the value of attribute album_ids.
-
#id ⇒ Object
Returns the value of attribute id.
-
#post_ids ⇒ Object
Returns the value of attribute post_ids.
-
#token ⇒ Object
Returns the value of attribute token.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#vk_client ⇒ Object
readonly
Vk client.
Instance Method Summary collapse
-
#albums_user_photo_count ⇒ Integer
Count user photos in albums.
-
#initialize(params = {}) ⇒ Group
constructor
Initialize.
-
#member? ⇒ Boolean
Check user is member.
-
#members ⇒ Array
Members ids.
-
#posts_user_comment_count ⇒ Integer
Count user comments in posts.
-
#posts_user_like_count ⇒ Integer
Count user likes in posts.
-
#posts_user_repost_count ⇒ Integer
Count user reposts in posts.
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_ids ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/snp_vk_parser/group.rb', line 7 def id @id end |
#post_ids ⇒ Object
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 |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/snp_vk_parser/group.rb', line 7 def token @token end |
#user_id ⇒ Object
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_client ⇒ Object (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_count ⇒ Integer
Count user photos in albums.
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.
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 |
#members ⇒ Array
Members 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_count ⇒ Integer
Count user comments in posts.
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_count ⇒ Integer
Count user likes in posts.
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_count ⇒ Integer
Count user reposts in posts.
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 |