Class: Twterm::Friendship

Inherits:
Object
  • Object
show all
Defined in:
lib/twterm/friendship.rb

Constant Summary collapse

STATUSES =
%i(
  blocking
  following
  following_requested
  muting
).freeze
@@instances =
[]
@@user_ids =
Set.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, from, to) ⇒ Friendship

Returns a new instance of Friendship.



15
16
17
18
19
20
21
# File 'lib/twterm/friendship.rb', line 15

def initialize(status, from, to)
  fail ArgumentError,
    '' unless STATUSES.include? status

  @status, @from, @to = status, from, to
  @@instances << self
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



10
11
12
# File 'lib/twterm/friendship.rb', line 10

def from
  @from
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/twterm/friendship.rb', line 10

def status
  @status
end

#toObject (readonly)

Returns the value of attribute to.



10
11
12
# File 'lib/twterm/friendship.rb', line 10

def to
  @to
end

Class Method Details

.already_looked_up?(user_id) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/twterm/friendship.rb', line 39

def self.already_looked_up?(user_id)
  @@user_ids.include?(user_id)
end

.block(from, to) ⇒ Object



43
44
45
# File 'lib/twterm/friendship.rb', line 43

def self.block(from, to)
  new(:blocking, from, to)
end

.blocking?(from, to) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/twterm/friendship.rb', line 47

def self.blocking?(from, to)
  !find(:blocking, from, to).nil?
end

.cancel_follow_request(from, to) ⇒ Object



51
52
53
# File 'lib/twterm/friendship.rb', line 51

def self.cancel_follow_request(from, to)
  new(:following_requested, from, to)
end

.follow(from, to) ⇒ Object



67
68
69
# File 'lib/twterm/friendship.rb', line 67

def self.follow(from, to)
  new(:following, from, to)
end

.following?(from, to) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/twterm/friendship.rb', line 71

def self.following?(from, to)
  !find(:following, from, to).nil?
end

.following_not_requested(from, to) ⇒ Object



75
76
77
# File 'lib/twterm/friendship.rb', line 75

def self.following_not_requested(from, to)
  delete(:following_requested, from, to)
end

.following_requested(from, to) ⇒ Object



79
80
81
# File 'lib/twterm/friendship.rb', line 79

def self.following_requested(from, to)
  new(:following_requested, from, to)
end

.following_requested?(from, to) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/twterm/friendship.rb', line 83

def self.following_requested?(from, to)
  !find(:following_requested, from, to).nil?
end

.looked_up!(user_id) ⇒ Object



87
88
89
90
# File 'lib/twterm/friendship.rb', line 87

def self.looked_up!(user_id)
  @@user_ids << user_id
  user_id
end

.mute(from, to) ⇒ Object



92
93
94
# File 'lib/twterm/friendship.rb', line 92

def self.mute(from, to)
  new(:muting, from, to)
end

.muting?(from, to) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/twterm/friendship.rb', line 96

def self.muting?(from, to)
  !find(:muting, from, to).nil?
end

.unblock(from, to) ⇒ Object



106
107
108
# File 'lib/twterm/friendship.rb', line 106

def self.unblock(from, to)
  delete(:blocking, from, to)
end

.unfollow(from, to) ⇒ Object



110
111
112
# File 'lib/twterm/friendship.rb', line 110

def self.unfollow(from, to)
  delete(:following, from, to)
end

.unmute(from, to) ⇒ Object



114
115
116
# File 'lib/twterm/friendship.rb', line 114

def self.unmute(from, to)
  delete(:muting, from, to)
end

Instance Method Details

#blocking?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/twterm/friendship.rb', line 23

def blocking?
  status?(:blocking)
end

#following?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/twterm/friendship.rb', line 27

def following?
  status?(:following)
end

#following_requested?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/twterm/friendship.rb', line 31

def following_requested?
  status?(:following_requested)
end

#muting?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/twterm/friendship.rb', line 35

def muting?
  status?(:muting)
end