Sha256: 178365e574c856913d8eafbdb047cfa8f0754db07427c8fe2efde77e5d7c7fe5

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 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

    class << self
      attr_accessor :branch
    end

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

    def primary_product
      products.select { |p| p.id == primary_product_id }.first
    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

1 entries across 1 versions & 1 rubygems

Version Path
reviewed-0.0.9 lib/reviewed/article.rb