Sha256: 205aa1eac5aa2e9c05640efa959aa20c6fe954fd8ab0c8c9606d901cc0834c60

Contents?: true

Size: 1.19 KB

Versions: 84

Compression:

Stored size: 1.19 KB

Contents

require 'delegate'

class OutlineVideoPresenter < SimpleDelegator
  REQUIRED_ATTRIBUTES = [:enabled, :completed, :id, :duration, :url, :name]

  def initialize(video)
    super(video)
    check_attributes
  end

  def css_class
    css_classes = []
    css_classes << "disabled" if !video.enabled
    css_classes << "completed" if video.completed

    css_classes.join(" ")
  end

  def slug
    "video_#{video.id}"
  end

  def duration
    minutes = (video.duration.to_f / 1000.0 / 60.0).floor
    remainder = (video.duration - (minutes * 60 * 1000))
    seconds = (remainder.to_f / 1000.0).floor

    if seconds <= 9
      seconds = "0#{seconds}"
    end

    "#{minutes}:#{seconds}"
  end

  def completed
    yield if video.completed
  end

  def url
    if video.enabled
      video.url
    else
      "#"
    end
  end

  private

  def check_attributes
    raise "Rendering a video requires: #{missing_attributes}" if missing_attributes?
  end

  def missing_attributes?
    REQUIRED_ATTRIBUTES.find do |attr|
      !__getobj__.respond_to?(attr)
    end
  end

  def missing_attributes
    REQUIRED_ATTRIBUTES.select do |attr|
      !__getobj__.respond_to?(attr)
    end
  end

  def video
    __getobj__
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
woople-theme-0.6.2 app/presenters/outline_video_presenter.rb
woople-theme-0.6.1 app/presenters/outline_video_presenter.rb
woople-theme-0.6 app/presenters/outline_video_presenter.rb
woople-theme-0.5.17 app/presenters/outline_video_presenter.rb
woople-theme-0.5.16 app/presenters/outline_video_presenter.rb
woople-theme-0.5.15 app/presenters/outline_video_presenter.rb
woople-theme-0.5.14 app/presenters/outline_video_presenter.rb
woople-theme-0.5.13 app/presenters/outline_video_presenter.rb
woople-theme-0.5.12 app/presenters/outline_video_presenter.rb
woople-theme-0.5.11 app/presenters/outline_video_presenter.rb
woople-theme-0.5.10 app/presenters/outline_video_presenter.rb
woople-theme-0.5.9 app/presenters/outline_video_presenter.rb
woople-theme-0.5.8 app/presenters/outline_video_presenter.rb
woople-theme-0.5.7 app/presenters/outline_video_presenter.rb
woople-theme-0.5.6 app/presenters/outline_video_presenter.rb
woople-theme-0.5.5 app/presenters/outline_video_presenter.rb
woople-theme-0.5.4 app/presenters/outline_video_presenter.rb
woople-theme-0.5.3 app/presenters/outline_video_presenter.rb
woople-theme-0.5.2 app/presenters/outline_video_presenter.rb
woople-theme-0.5.0.1 app/presenters/outline_video_presenter.rb