Class: Socialcastr::Comment

Inherits:
Base
  • Object
show all
Defined in:
lib/socialcastr/comment.rb

Instance Attribute Summary

Attributes inherited from Base

#prefix_options

Instance Method Summary collapse

Methods inherited from Base

all, api, #api, collection_name, collection_path, #collection_path, #copy_attributes_from_object, #create, #destroy, #element_path, element_path, find, find_every, find_single, first, from_hash, #id, #initialize, last, #method_missing, #method_name, model_name, #new?, #param_name, parse, parse_options, prefix, #refresh, #save, set_prefix_options, #to_params, #to_prefix_options, #update

Constructor Details

This class inherits a constructor from Socialcastr::Base

Dynamic Method Handling

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

Instance Method Details

#likable_by?(api_id) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/socialcastr/comment.rb', line 19

def likable_by?(api_id)
  return false if self.user.id == api_id
  like_for(api_id).nil?
end

#like!Object



3
4
5
6
7
# File 'lib/socialcastr/comment.rb', line 3

def like!
  Socialcastr::Like.new({}, to_prefix_options).save
  refresh
  return self
end

#like_for(api_id) ⇒ Object



24
25
26
27
# File 'lib/socialcastr/comment.rb', line 24

def like_for(api_id)
  return nil if (self.likes.nil? || self.likes.empty?)
  self.likes.select { |like| like.unlikable_by?(api_id) }.first
end

#unlikable_by?(api_id) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/socialcastr/comment.rb', line 15

def unlikable_by?(api_id)
  self.likes.map{|l| l.unlikable_by?(api_id)}.any?
end

#unlike!Object



9
10
11
12
13
# File 'lib/socialcastr/comment.rb', line 9

def unlike!
  like.destroy
  refresh
  return self
end