Sha256: 47394c96b0070f01ff57103fdc528baf186a44e614f18d2ad62834e1c8c61c97

Contents?: true

Size: 661 Bytes

Versions: 3

Compression:

Stored size: 661 Bytes

Contents

module Reviewed
  class Article < Base
    def find_page(slug)
      pages.find { |page| page.slug.match(/#{slug}/i) }
    end

    def products
      (@attributes[:products] || []).map do |product|
        Reviewed::Product.new(product)
      end
    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

3 entries across 3 versions & 1 rubygems

Version Path
reviewed-0.0.6 lib/reviewed/article.rb
reviewed-0.0.5 lib/reviewed/article.rb
reviewed-0.0.4 lib/reviewed/article.rb