Class: Postage::Post
- Inherits:
-
Object
- Object
- Postage::Post
- Defined in:
- lib/postage/post.rb
Overview
end_content
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file ⇒ Object
readonly
Post text file.
-
#filter ⇒ Object
readonly
Filter for render post file.
-
#path ⇒ Object
readonly
Post file path.
-
#publish_date ⇒ Object
readonly
Post publish date, of course.
-
#summary ⇒ Object
readonly
Summary is a first paragraph of content.
-
#tags ⇒ Object
readonly
Tags accepts only one word per tag.
-
#title ⇒ Object
readonly
The title accepts Markdown syntax.
Class Method Summary collapse
-
.load(file_name) ⇒ Object
Load all attributes from file name and read content.
Instance Method Summary collapse
-
#<=>(post) ⇒ Object
Sort posts by format.
-
#build_file ⇒ Object
Build post file name and return following format: yyyymmdd-post_name.tags.separated.by.points.filter.
-
#create_into(directory) ⇒ Object
Get post file name and creates content and save into directory.
-
#extract_attributes(file_name) ⇒ Object
Check and extract all attributes from file name.
-
#initialize(options = {}) ⇒ Post
constructor
Initialize new post using options.
-
#matched?(regexp) ⇒ Boolean
Test pattern in title or filename.
-
#to_s ⇒ Object
Return post name formatted (“year/month/day/name”).
Constructor Details
#initialize(options = {}) ⇒ Post
Initialize new post using options.
51 52 53 |
# File 'lib/postage/post.rb', line 51 def initialize( = {}) .instance_variables_set_to(self) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
40 41 42 |
# File 'lib/postage/post.rb', line 40 def content @content end |
#file ⇒ Object (readonly)
Post text file
45 46 47 |
# File 'lib/postage/post.rb', line 45 def file @file end |
#filter ⇒ Object (readonly)
Filter for render post file.
42 43 44 |
# File 'lib/postage/post.rb', line 42 def filter @filter end |
#path ⇒ Object (readonly)
Post file path
48 49 50 |
# File 'lib/postage/post.rb', line 48 def path @path end |
#publish_date ⇒ Object (readonly)
Post publish date, of course.
33 34 35 |
# File 'lib/postage/post.rb', line 33 def publish_date @publish_date end |
#summary ⇒ Object (readonly)
Summary is a first paragraph of content.
39 40 41 |
# File 'lib/postage/post.rb', line 39 def summary @summary end |
#tags ⇒ Object (readonly)
Tags accepts only one word per tag.
37 38 39 |
# File 'lib/postage/post.rb', line 37 def @tags end |
#title ⇒ Object (readonly)
The title accepts Markdown syntax.
35 36 37 |
# File 'lib/postage/post.rb', line 35 def title @title end |
Class Method Details
.load(file_name) ⇒ Object
Load all attributes from file name and read content.
56 57 58 |
# File 'lib/postage/post.rb', line 56 def self.load(file_name) new.extract_attributes(file_name) end |
Instance Method Details
#<=>(post) ⇒ Object
Sort posts by format.
100 101 102 |
# File 'lib/postage/post.rb', line 100 def <=>(post) to_s <=> post.to_s end |
#build_file ⇒ Object
Build post file name and return following format: yyyymmdd-post_name.tags.separated.by.points.filter
81 82 83 |
# File 'lib/postage/post.rb', line 81 def build_file @file = "#{build_publish_date}-#{build_file_name}.#{}.#{build_filter}" end |
#create_into(directory) ⇒ Object
Get post file name and creates content and save into directory.
86 87 88 89 90 91 92 |
# File 'lib/postage/post.rb', line 86 def create_into(directory) build_file Pathname.new(directory).join(@file).open 'w+' do |file| post = self file << ERB.new(load_template).result(binding) end end |
#extract_attributes(file_name) ⇒ Object
Check and extract all attributes from file name.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/postage/post.rb', line 61 def extract_attributes(file_name) extract_publish_date(file_name) (file_name) extract_filter(file_name) extract_title_and_content(file_name) @path = Pathname.new(file_name) @file = @path.to_s @title = @file.gsub('_', ' ').capitalize if @title.to_s.empty? @summary = @content.match(%r{<p>.*</p>}).to_s self end |
#matched?(regexp) ⇒ Boolean
Test pattern in title or filename.
95 96 97 |
# File 'lib/postage/post.rb', line 95 def matched?(regexp) @title.match(regexp) || @file.match(regexp) end |
#to_s ⇒ Object
Return post name formatted (“year/month/day/name”).
74 75 76 77 78 |
# File 'lib/postage/post.rb', line 74 def to_s @file.to_s.scan(%r{(\d{4})(\d{2})(\d{2})(.*?)-(.*?)\..*}) do |year,month,day,time,name| return "#{year}/#{month}/#{day}/#{name}" end end |