lib/reviewed/article.rb in reviewed-0.0.6 vs lib/reviewed/article.rb in reviewed-0.0.7
- old
+ new
@@ -1,28 +1,30 @@
+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 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|
+ @attributes.attachments.select do |attachment|
attachment_tags = attachment.tags || []
attachment_tags.map(&:downcase).include?(tag.downcase)
end
else
- @attributes[:attachments]
+ @attributes.attachments
end
end
end
end