Class: UserData

Inherits:
Object
  • Object
show all
Defined in:
lib/botinsta/data/user_data.rb

Overview

Class handling user data. Takes a data object extended Hashie::Extensions::DeepFind

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ UserData

Returns a new instance of UserData.



7
8
9
10
11
12
13
14
# File 'lib/botinsta/data/user_data.rb', line 7

def initialize(data)
  @id              = data.deep_find('pk')
  @username        = data.deep_find('username')
  @full_name       = data.deep_find('full_name')
  @following_count = data.deep_find('following_count')
  @follower_count  = data.deep_find('follower_count')
  @is_private      = data.deep_find('is_private')
end

Instance Attribute Details

#follower_countObject (readonly)

Returns the value of attribute follower_count.



5
6
7
# File 'lib/botinsta/data/user_data.rb', line 5

def follower_count
  @follower_count
end

#following_countObject (readonly)

Returns the value of attribute following_count.



5
6
7
# File 'lib/botinsta/data/user_data.rb', line 5

def following_count
  @following_count
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



5
6
7
# File 'lib/botinsta/data/user_data.rb', line 5

def full_name
  @full_name
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/botinsta/data/user_data.rb', line 5

def id
  @id
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/botinsta/data/user_data.rb', line 5

def username
  @username
end

Instance Method Details

#delete_from_db(table) ⇒ Object



24
25
26
# File 'lib/botinsta/data/user_data.rb', line 24

def delete_from_db(table)
  table.where(user_id: @id).delete
end

#exists_in_db?(table) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/botinsta/data/user_data.rb', line 28

def exists_in_db?(table)
  !table.where(user_id: @id).empty?
end

#insert_into_db(table) ⇒ Object



20
21
22
# File 'lib/botinsta/data/user_data.rb', line 20

def insert_into_db(table)
  table.insert(user_id: @id, username: @username, follow_time: Time.now)
end

#private?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/botinsta/data/user_data.rb', line 16

def private?
  @is_private
end