Class: UserData
- Inherits:
-
Object
- Object
- UserData
- 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
-
#follower_count ⇒ Object
readonly
Returns the value of attribute follower_count.
-
#following_count ⇒ Object
readonly
Returns the value of attribute following_count.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #delete_from_db(table) ⇒ Object
- #exists_in_db?(table) ⇒ Boolean
-
#initialize(data) ⇒ UserData
constructor
A new instance of UserData.
- #insert_into_db(table) ⇒ Object
- #private? ⇒ Boolean
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_count ⇒ Object (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_count ⇒ Object (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_name ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/botinsta/data/user_data.rb', line 5 def id @id end |
#username ⇒ Object (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
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
16 17 18 |
# File 'lib/botinsta/data/user_data.rb', line 16 def private? @is_private end |