Class: MediaData

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#shortcodeObject (readonly)

Returns the value of attribute shortcode.



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

def shortcode
  @shortcode
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

#textObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/botinsta/data/media_data.rb', line 27

def video?
  @is_video
end