Sha256: e4b0c06f0df5a55a401dc101495496bc58c7cf7ba8f53996b065f72fe095693a

Contents?: true

Size: 1012 Bytes

Versions: 2

Compression:

Stored size: 1012 Bytes

Contents

# Class handling media data.
# Takes a data object extended Hashie::Extensions::DeepFind
class MediaData

  attr_reader :id, :owner, :text, :shortcode, :tags

  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.scan(/#[a-zA-Z0-9]+/)
    @shortcode          = data.deep_find('shortcode')

  end

  def comments_disabled?
    @comments_disabled
  end

  def blacklisted_tag?(tag_blacklist)
    !(@tags & tag_blacklist).empty?
  end

  def video?
    @is_video
  end

  def insert_into_db(table)
    table.insert(media_id: @id, user_id: @owner, shortcode: @shortcode, like_time: Time.now)
  end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
botinsta-0.1.2 lib/botinsta/data/media_data.rb
botinsta-0.1.1 lib/botinsta/data/media_data.rb