Class: Postage::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/postage/finder.rb

Overview

This class is a utility for find all posts in specific directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tagsObject (readonly)

Post tags list



11
12
13
# File 'lib/postage/finder.rb', line 11

def tags
  @tags
end

Instance Method Details

#all_post_tagsObject



43
44
45
46
# File 'lib/postage/finder.rb', line 43

def 
  all_posts
  @tags ||= @posts.collect{ |post| post.tags }.flatten.uniq.sort
end

#all_postsObject



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.tags.include?(tag) }
end

#all_tagsObject



48
49
50
# File 'lib/postage/finder.rb', line 48

def all_tags
  
end

#load_all_post_filesObject



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)
  all_tags
  @tags.find{ |tag| tag == name }
end