Sha256: 0645552c8b523b6305571210829911cd9ab353c90494afd344a5385c9bf84809

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require_relative 'base'
require_relative 'tag_group'

class WCC::Media::Message < WCC::Media::Base
  active_record_shim do
    endpoint 'messages'
    filters %w[
      on_or_after_date
      on_or_before_date
      tag_id
      speaker_id
      scripture_book_id
      series_id
      title_like
      legacy_id
    ].freeze
  end

  %w[
    date
    duration
    title
    subtitle
    description
    series_position
    slug
    campus_names
    topic
    topics
  ].each do |att|
    define_method att do
      raw[att]
    end
  end

  def speakers
    (raw['speakers'] || []).map { |val| WCC::Media::Speaker.new(val) }
  end

  def tags
    (raw['tags'] || []).map { |val| WCC::Media::Tag.new(val) }
  end

  %w[
    scripture_references
    downloads
  ].each do |att|
    define_method att do
      (raw[att] || []).map { |val| OpenStruct.new(val) }
    end
  end

  def series
    WCC::Media::Series.new(raw['series']) if raw['series']
  end

  %w[
    meta
    embeds
    assets
    images
    external_urls
    transcript
    sermon_guide
    _clips
    _formatted
    _stats
  ].each do |att|
    define_method att do
      OpenStruct.new(raw[att]) if raw[att]
    end
  end

  def has_video? # rubocop:disable Naming/PredicateName
    assets.each_pair
      .any? { |k, v| /video/.match(k) && v && !v.empty? }
  end

  def to_param
    "#{id}-#{slug}"
  end

  WCC::Media::TagGroup.all.each do |tag_group|
    define_method(tag_group.name.downcase) do
      tags.select { |t| t.tag_group == tag_group }
    end
  end
  # pluralize "campus" specifically
  alias_method :campuses, :campus
  remove_method :campus
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wcc-media-client-0.4.8 lib/wcc/media/message.rb