Class: MediaData
- Inherits:
-
Object
- Object
- MediaData
- Defined in:
- lib/botinsta/data/media_data.rb
Overview
Class handling media data. Takes a data object extended Hashie::Extensions::DeepFind
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#shortcode ⇒ Object
readonly
Returns the value of attribute shortcode.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #blacklisted_tag?(tag_blacklist) ⇒ Boolean
- #comments_disabled? ⇒ Boolean
- #delete_from_db(table) ⇒ Object
- #exists_in_db?(table) ⇒ Boolean
-
#initialize(data) ⇒ MediaData
constructor
A new instance of MediaData.
- #insert_into_db(table) ⇒ Object
- #video? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ MediaData
Returns a new instance of MediaData.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/botinsta/data/media_data.rb', line 7 def initialize(data) @id = data.deep_find('id') @owner = data.deep_find('owner')['id'] @is_video = data.deep_find('is_video') @comments_disabled = data.deep_find('comments_disabled') @text = data.deep_find('text') @tags = @text.nil? ? [] : @text.scan(/#[a-zA-Z0-9]+/) @shortcode = data.deep_find('shortcode') end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/botinsta/data/media_data.rb', line 5 def id @id end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
5 6 7 |
# File 'lib/botinsta/data/media_data.rb', line 5 def owner @owner end |
#shortcode ⇒ Object (readonly)
Returns the value of attribute shortcode.
5 6 7 |
# File 'lib/botinsta/data/media_data.rb', line 5 def shortcode @shortcode end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
5 6 7 |
# File 'lib/botinsta/data/media_data.rb', line 5 def @tags end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/botinsta/data/media_data.rb', line 5 def text @text end |
Instance Method Details
#blacklisted_tag?(tag_blacklist) ⇒ Boolean
23 24 25 |
# File 'lib/botinsta/data/media_data.rb', line 23 def blacklisted_tag?(tag_blacklist) !(@tags & tag_blacklist).empty? end |
#comments_disabled? ⇒ Boolean
19 20 21 |
# File 'lib/botinsta/data/media_data.rb', line 19 def comments_disabled? @comments_disabled end |
#delete_from_db(table) ⇒ Object
35 36 37 |
# File 'lib/botinsta/data/media_data.rb', line 35 def delete_from_db(table) table.where(media_id: @id).delete end |
#exists_in_db?(table) ⇒ Boolean
39 40 41 |
# File 'lib/botinsta/data/media_data.rb', line 39 def exists_in_db?(table) !table.where(media_id: @id).empty? end |
#insert_into_db(table) ⇒ Object
31 32 33 |
# File 'lib/botinsta/data/media_data.rb', line 31 def insert_into_db(table) table.insert(media_id: @id, user_id: @owner, shortcode: @shortcode, like_time: Time.now) end |
#video? ⇒ Boolean
27 28 29 |
# File 'lib/botinsta/data/media_data.rb', line 27 def video? @is_video end |