Class: Postage::Finder
- Inherits:
-
Object
- Object
- Postage::Finder
- Defined in:
- lib/postage/finder.rb
Overview
This class is a utility for find all posts in specific directory.
Instance Attribute Summary collapse
-
#posts(keywords) ⇒ Object
readonly
Post list.
-
#tags ⇒ Object
readonly
Post tags list.
Instance Method Summary collapse
- #all_post_tags ⇒ Object
- #all_posts ⇒ Object
- #all_posts_by_tag(tag) ⇒ Object
- #all_tags ⇒ Object
-
#initialize(directory) ⇒ Finder
constructor
Finder most be initialized with the directory that contains post files.
- #load_all_post_files ⇒ Object
- #post(year, month, day, name) ⇒ Object
- #tag(name) ⇒ Object
Constructor Details
#initialize(directory) ⇒ Finder
Finder most be initialized with the directory that contains post files.
14 15 16 |
# File 'lib/postage/finder.rb', line 14 def initialize(directory) @files = Dir[File.join(directory, "**.*")] end |
Instance Attribute Details
#posts(keywords) ⇒ Object (readonly)
Post list
8 9 10 |
# File 'lib/postage/finder.rb', line 8 def posts @posts end |
#tags ⇒ Object (readonly)
Post tags list
11 12 13 |
# File 'lib/postage/finder.rb', line 11 def @tags end |
Instance Method Details
#all_post_tags ⇒ Object
43 44 45 46 |
# File 'lib/postage/finder.rb', line 43 def all_posts @tags ||= @posts.collect{ |post| post. }.flatten.uniq.sort end |
#all_posts ⇒ Object
24 25 26 |
# File 'lib/postage/finder.rb', line 24 def all_posts @posts ||= load_all_post_files end |
#all_posts_by_tag(tag) ⇒ Object
28 29 30 31 |
# File 'lib/postage/finder.rb', line 28 def all_posts_by_tag(tag) all_posts @posts.find_all{ |post| post..include?(tag) } end |
#all_tags ⇒ Object
48 49 50 |
# File 'lib/postage/finder.rb', line 48 def end |
#load_all_post_files ⇒ Object
18 19 20 21 22 |
# File 'lib/postage/finder.rb', line 18 def load_all_post_files @files.sort.collect do |file_name| Post.load(file_name) end end |
#post(year, month, day, name) ⇒ Object
33 34 35 36 |
# File 'lib/postage/finder.rb', line 33 def post(year, month, day, name) all_posts @posts.find{ |post| post.file.match(%r{#{year}#{month}#{day}-#{name}*.*}i) } end |
#tag(name) ⇒ Object
52 53 54 55 |
# File 'lib/postage/finder.rb', line 52 def tag(name) @tags.find{ |tag| tag == name } end |