Class: Hashup::Post
- Inherits:
-
Object
- Object
- Hashup::Post
- Defined in:
- lib/hashup/post.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#date ⇒ Object
Returns the value of attribute date.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(post) ⇒ Post
constructor
A new instance of Post.
- #parse_post(post) ⇒ Object
Constructor Details
#initialize(post) ⇒ Post
Returns a new instance of Post.
6 7 8 9 10 11 12 |
# File 'lib/hashup/post.rb', line 6 def initialize post self.parse_post post @filename = "#{File.basename(post,".ma")}.html" @title = @metadata["title"] @date = @metadata["date"] @tags = @metadata["tags"] end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
5 6 7 |
# File 'lib/hashup/post.rb', line 5 def contents @contents end |
#date ⇒ Object
Returns the value of attribute date.
5 6 7 |
# File 'lib/hashup/post.rb', line 5 def date @date end |
#filename ⇒ Object
Returns the value of attribute filename.
5 6 7 |
# File 'lib/hashup/post.rb', line 5 def filename @filename end |
#metadata ⇒ Object
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/hashup/post.rb', line 5 def @metadata end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/hashup/post.rb', line 5 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/hashup/post.rb', line 5 def title @title end |
Instance Method Details
#parse_post(post) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/hashup/post.rb', line 14 def parse_post post contents= File.open(post).read if(md = contents.match(/^(?<metadata>---\s*\n.*?\n?)^(---\s*$\n?)/m)) @contents = ::Markascend.compile md.post_match, toc: true @metadata = YAML.load(md[:metadata]) end end |