rollin 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6ef7f3be9c83a460825f763d4c06d1b2b0ac1a6
4
- data.tar.gz: ab3c26c1af266bb7ca8caf4ef57e9e6c15b02548
3
+ metadata.gz: 049730c65afc7a862413afa2d4cb68e79ce28adb
4
+ data.tar.gz: 3dd7bd4326661904a43a8ad20c544fa4c738ffb3
5
5
  SHA512:
6
- metadata.gz: 5b52239b44ea70fd8e6d887f36958600aaa4183ee42bb34a2b3212a1cbb73919f1ba111b26f19ca688877d23c0bdc36d83e844189c6770ba48a18c7a78d37b37
7
- data.tar.gz: e4c68146f52c7edce5aad218527fcf0e06b4011cc4569ff36a47fe1615c5eee9ab5e1239b1defce396f71df57bb0e2655a208051e67718b010d79c0d26de7f2e
6
+ metadata.gz: d7d53f585e4e0493a00f526def30670eb2b95fff27d5c21479e5986965510009dd52341eb4c1d5f4ff249cbf648d433a25bb4ba0ddc5b042a26dbcf1fe567bce
7
+ data.tar.gz: 88612276e7ffe27f8e84f546bd99aa7e6e3eed8cc8b5dd90fc53fd9f5ce3a7411bb6886aa21c0a4e9e8c361de201cad0e1243656408106e73d80360ebde7a18f
data/README.md CHANGED
@@ -21,7 +21,7 @@ First you will need to have the following structure in your filesystem.
21
21
  ├── my_posts
22
22
  └── 2013_05_01_My_first_post.mk
23
23
 
24
- ### Getting articles
24
+ ### Getting the articles
25
25
 
26
26
  In your code.
27
27
 
@@ -29,12 +29,14 @@ In your code.
29
29
 
30
30
  anArticle = blog.articles.first
31
31
 
32
+ anArticle.id # => "2013_05_01_My_first_post"
33
+ anArticle.title # => "My first post"
34
+ anArticle.body # => "<h3>My first post!</h3>\n<p>blah blah blah</p>"
35
+
32
36
  anArticle.date # => #<Date: 2013-05-01 ((2456414j,0s,0n),+0s,2299161j)>
33
37
  anArticle.year # => 2013
34
38
  anArticle.month # => 05
35
39
  anArticle.day # => 01
36
- anArticle.title # => "My first post"
37
- anArticle.body # => "<h3>My first post!</h3>\n<p>blah blah blah</p>"
38
40
 
39
41
  ### Getting the archive
40
42
 
@@ -44,6 +46,10 @@ In your code.
44
46
  a_monthly_archive.month # => 5
45
47
  a_monthly_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
46
48
 
49
+ ### Finding an article
50
+
51
+ blog.find_article_by_id('2013_05_01_My_first_post') # => #Rollin::Article(:title => "My first post" ...)
52
+
47
53
  ## Build status
48
54
 
49
55
  [![Build Status](https://travis-ci.org/marano/rollin.png)](https://travis-ci.org/marano/rollin)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
data/lib/rollin/blog.rb CHANGED
@@ -13,27 +13,18 @@ class Rollin::Blog
13
13
  end
14
14
  end
15
15
 
16
- def monthly_archive
17
- years = {}
18
- articles.each do |article|
19
- if years.has_key?(article.year)
20
- year = years[article.year]
21
- if year.has_key?(article.month)
22
- year[article.month] << article
23
- else
24
- year[article.month] = [ article ]
25
- end
26
- else
27
- years[article.year] = { article.month => [ article ] }
28
- end
16
+ def annually_archive
17
+ monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
18
+ Rollin::YearArchive.new(year, monthly_archive.map { |aMonth| aMonth.year == year })
29
19
  end
30
- archives_list = []
31
- years.each do |year, months|
32
- months.each do |month|
33
- month_articles = articles.map { |article| article.year == year && article.month == month }
34
- archives_list << Rollin::MonthArchive.new(year, month, month_articles)
35
- end
20
+ end
21
+
22
+ def monthly_archive
23
+ articles.map { |article| [article.year, article.month] }.uniq.map do |year_and_month|
24
+ year = year_and_month[0]
25
+ month = year_and_month[1]
26
+ articles_for_month = articles.map { |anArticle| anArticle.year == year && anArticle.month }
27
+ Rollin::MonthArchive.new(year, month, articles_for_month)
36
28
  end
37
- return archives_list
38
29
  end
39
30
  end
@@ -0,0 +1,11 @@
1
+ class Rollin::YearArchive
2
+ attr_reader :year, :monthly_archive
3
+
4
+ def initialize(year, monthly_archive)
5
+ @year, @monthly_archive = year, monthly_archive
6
+ end
7
+
8
+ def articles
9
+ monthly_archive.map { |month_archive| month_archive.articles }.flatten
10
+ end
11
+ end
data/lib/rollin.rb CHANGED
@@ -5,6 +5,7 @@ require "rollin/version"
5
5
  require "rollin/blog"
6
6
  require "rollin/article"
7
7
  require "rollin/month_archive"
8
+ require "rollin/year_archive"
8
9
 
9
10
  module Rollin
10
11
  end
data/spec/blog_spec.rb CHANGED
@@ -5,11 +5,15 @@ describe Rollin::Blog do
5
5
  subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures/articles') }
6
6
 
7
7
  it 'has the right amount of articles' do
8
- blog.articles.size.should == 3
8
+ blog.articles.size.should == 4
9
9
  end
10
10
 
11
11
  it 'has the right amount of monthly archives' do
12
- blog.monthly_archive.size.should == 2
12
+ blog.monthly_archive.size.should == 3
13
+ end
14
+
15
+ it 'has the right amount of yearly archives' do
16
+ blog.annually_archive.size.should == 2
13
17
  end
14
18
 
15
19
  it 'finds article by its id' do
@@ -0,0 +1,17 @@
1
+ describe Rollin::YearArchive do
2
+ let (:article) { Rollin::Article.new('spec/fixtures/2013_05_01_My_first_post.mk') }
3
+ subject (:month_archive) { Rollin::MonthArchive.new(2013, 05, [ article ]) }
4
+ subject (:year_archive) { Rollin::YearArchive.new(2013, [ month_archive ]) }
5
+
6
+ it 'tells the year' do
7
+ year_archive.year.should == 2013
8
+ end
9
+
10
+ it 'has monthly archives' do
11
+ year_archive.monthly_archive.size.should == 1
12
+ end
13
+
14
+ it 'has a list of articles' do
15
+ year_archive.articles.first.should == article
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - marano
@@ -100,14 +100,17 @@ files:
100
100
  - lib/rollin/blog.rb
101
101
  - lib/rollin/month_archive.rb
102
102
  - lib/rollin/version.rb
103
+ - lib/rollin/year_archive.rb
103
104
  - rollin.gemspec
104
105
  - spec/article_spec.rb
105
106
  - spec/blog_spec.rb
106
107
  - spec/fixtures/articles/2013_05_01_My_first_post.mk
107
108
  - spec/fixtures/articles/2013_05_02_My_second_post.mk
108
109
  - spec/fixtures/articles/2013_06_01_My_third_post.mk
110
+ - spec/fixtures/articles/2014_01_01_My_fourth_post.mk
109
111
  - spec/month_archive_spec.rb
110
112
  - spec/spec_helper.rb
113
+ - spec/year_archive_spec.rb
111
114
  homepage: http://github.com/marano/rollin
112
115
  licenses:
113
116
  - MIT
@@ -138,5 +141,7 @@ test_files:
138
141
  - spec/fixtures/articles/2013_05_01_My_first_post.mk
139
142
  - spec/fixtures/articles/2013_05_02_My_second_post.mk
140
143
  - spec/fixtures/articles/2013_06_01_My_third_post.mk
144
+ - spec/fixtures/articles/2014_01_01_My_fourth_post.mk
141
145
  - spec/month_archive_spec.rb
142
146
  - spec/spec_helper.rb
147
+ - spec/year_archive_spec.rb