Sha256: 39e93383b130ff3ac4d3dbb820fd089164f894c5645cbf4915b824c396023481

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

require 'reviewed/page'
require 'reviewed/product'
require 'reviewed/attachment'

module Reviewed
  class Article < Base
    has_many :pages
    has_many :products
    has_many :attachments

    def find_page(slug)
      pages.find { |page| page.slug.match(/#{slug}/i) }
    end

    def primary_product
      if respond_to?(:products)
        products.select { |p| p.id == primary_product_id }.first
      end
    end

    def attachments(tag=nil)
      if tag.present?
        @attributes.attachments.select do |attachment|
          attachment_tags = attachment.tags || []
          attachment_tags.map(&:downcase).include?(tag.downcase)
        end
      else
        @attributes.attachments
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reviewed-0.2.0 lib/reviewed/article.rb
reviewed-0.1.4 lib/reviewed/article.rb
reviewed-0.1.32 lib/reviewed/article.rb