Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Search by date uses the same api as other searches.

  • Loading branch information...
commit 5ae7601d33c5adfaeeb364c31b30f589cb296400 1 parent f122d05
@marano authored
Showing with 23 additions and 12 deletions.
  1. +20 −3 lib/rollin/article.rb
  2. +0 −6 lib/rollin/blog.rb
  3. +3 −3 spec/rollin_spec.rb
View
23 lib/rollin/article.rb
@@ -16,11 +16,28 @@ def title
end
def matches?(search)
+ search = search.clone
+
return true if @id == search
- search.each do |key, value|
- return true if metatags[key] != nil && (metatags[key] == value || metatags[key].include?(value))
+
+ if search.has_key?(:year)
+ return false if search.delete(:year) != @year
+ if search.has_key?(:month)
+ return false if search.delete(:month) != @month
+ if search.has_key?(:day)
+ return false if search.delete(:day) != @day
+ end
+ end
+ end
+
+ if search.keys.empty?
+ return true
+ else
+ search.each do |key, value|
+ return true if metatags[key] != nil && (metatags[key] == value || metatags[key].include?(value))
+ end
+ return false
end
- return false
end
def metatags
View
6 lib/rollin/blog.rb
@@ -15,12 +15,6 @@ def articles(search=nil)
end
end
- def articles_by_publication(year, month=nil, day=nil)
- articles.select do |article|
- article.year == year && (month.nil? || article.month == month) && (day.nil? || day == article.day)
- end
- end
-
def annual_archive
monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
Rollin::YearArchive.new(year, monthly_archive.select { |aMonth| aMonth.year == year })
View
6 spec/rollin_spec.rb
@@ -55,9 +55,9 @@
end
it 'searches by date' do
- blog.articles_by_publication(2013).should include(first_article, second_article, third_article)
- blog.articles_by_publication(2013, 5).should include(first_article, second_article)
- blog.articles_by_publication(2013, 5, 1).should include(first_article)
+ blog.articles(year: 2013).should include(first_article, second_article, third_article)
+ blog.articles(year: 2013, month: 5).should include(first_article, second_article)
+ blog.articles(year: 2013, month: 5, day: 1).should include(first_article)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.