Class: Post
- Inherits:
-
Object
- Object
- Post
- Defined in:
- lib/persona/post.rb
Constant Summary collapse
- POST_FOLDER =
'./contents/posts'
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#excerpt ⇒ Object
readonly
Returns the value of attribute excerpt.
-
#is_excerpt ⇒ Object
readonly
Returns the value of attribute is_excerpt.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file_name) ⇒ Post
constructor
A new instance of Post.
Constructor Details
#initialize(file_name) ⇒ Post
Returns a new instance of Post.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/persona/post.rb', line 7 def initialize(file_name) f = File.open("#{POST_FOLDER}/#{file_name}","r") @content = f.content_as_string @title = f. 'title' @author = f. 'author' @date = Date.strptime(f.('date'), '%Y/%m/%d') @excerpt = create_excerpt(@content) splits = /(\d{4}-\d{2}-\d{2})-([^\/]*)\.txt$/.match file_name if splits @url = splits[1].gsub(/[-]/, "/") + "/" + splits[2] + "/" end f.close end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def @author end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def content @content end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def date @date end |
#excerpt ⇒ Object (readonly)
Returns the value of attribute excerpt.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def excerpt @excerpt end |
#is_excerpt ⇒ Object (readonly)
Returns the value of attribute is_excerpt.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def is_excerpt @is_excerpt end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/persona/post.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/persona/post.rb', line 27 def self.all posts = Dir.entries("#{POST_FOLDER}").sort.reverse.reject do |it| not it.end_with? '.txt' end posts.map do |it| Post.new it end end |