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
Returns the value of attribute file.
-
#filter ⇒ Object
readonly
Filter for render post file.
-
#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
-
#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
-
#to_s ⇒ Object
Return post name formatted (“year/month/day/name”).
Constructor Details
#initialize(options = {}) ⇒ Post
Initialize new post using options.
45 46 47 |
# File 'lib/postage/post.rb', line 45 def initialize( = {}) .instance_variables_set_to(self) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
39 40 41 |
# File 'lib/postage/post.rb', line 39 def content @content end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
42 43 44 |
# File 'lib/postage/post.rb', line 42 def file @file end |
#filter ⇒ Object (readonly)
Filter for render post file.
41 42 43 |
# File 'lib/postage/post.rb', line 41 def filter @filter end |
#publish_date ⇒ Object (readonly)
Post publish date, of course.
32 33 34 |
# File 'lib/postage/post.rb', line 32 def publish_date @publish_date end |
#summary ⇒ Object (readonly)
Summary is a first paragraph of content.
38 39 40 |
# File 'lib/postage/post.rb', line 38 def summary @summary end |
#tags ⇒ Object (readonly)
Tags accepts only one word per tag.
36 37 38 |
# File 'lib/postage/post.rb', line 36 def @tags end |
#title ⇒ Object (readonly)
The title accepts Markdown syntax.
34 35 36 |
# File 'lib/postage/post.rb', line 34 def title @title end |
Class Method Details
.load(file_name) ⇒ Object
Load all attributes from file name and read content.
50 51 52 |
# File 'lib/postage/post.rb', line 50 def self.load(file_name) new.extract_attributes(file_name) end |
Instance Method Details
#build_file ⇒ Object
Build post file name and return following format: yyyymmdd-post_name.tags.separated.by.points.filter
74 75 76 |
# File 'lib/postage/post.rb', line 74 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.
79 80 81 82 83 84 |
# File 'lib/postage/post.rb', line 79 def create_into(directory) File.open(File.join(directory, @file), 'a') 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.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/postage/post.rb', line 55 def extract_attributes(file_name) extract_publish_date(file_name) (file_name) extract_filter(file_name) extract_title_and_content(file_name) @file = File.basename(file_name) @title = @file.gsub('_', ' ').capitalize if @title.to_s.empty? @summary = @content.match(%r{<p>.*</p>}).to_s self end |
#matched?(regexp) ⇒ Boolean
86 87 88 |
# File 'lib/postage/post.rb', line 86 def matched?(regexp) @title.match(regexp) || @file.match(regexp) end |
#to_s ⇒ Object
Return post name formatted (“year/month/day/name”).
67 68 69 70 71 |
# File 'lib/postage/post.rb', line 67 def to_s @file.scan(%r{(\d{4})(\d{2})(\d{2})(.*?)-(.*?)\..*}) do |year,month,day,time,name| return "#{year}/#{month}/#{day}/#{name}" end end |