Class: Hashup::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/hashup/post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentsObject

Returns the value of attribute contents.



5
6
7
# File 'lib/hashup/post.rb', line 5

def contents
  @contents
end

#dateObject

Returns the value of attribute date.



5
6
7
# File 'lib/hashup/post.rb', line 5

def date
  @date
end

#filenameObject

Returns the value of attribute filename.



5
6
7
# File 'lib/hashup/post.rb', line 5

def filename
  @filename
end

#metadataObject

Returns the value of attribute metadata.



5
6
7
# File 'lib/hashup/post.rb', line 5

def 
  @metadata
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/hashup/post.rb', line 5

def tags
  @tags
end

#titleObject

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