Class: Post
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#html(link = "") ⇒ Object
Return the HTML rendering of the post.
-
#process ⇒ Object
Pull out metadata and markup the post.
- #to_s ⇒ Object
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Resource
Instance Method Details
#[](index) ⇒ Object
12 13 14 |
# File 'lib/den/post.rb', line 12 def [](index) @content[index] end |
#html(link = "") ⇒ Object
Return the HTML rendering of the post
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/den/post.rb', line 18 def html(link="") _html = "<div id=\"post\">\n" # Wrap title in anchor if link is provided _html += "<h1 id=\"title\">" if link != "" _html += "<a href=\"#{link}\">" end _html += "#{@content[:title]}" if link != "" _html += "</a>" end _html += "</h1>\n" # Add the rest of the necessary content _html += "<h2 id=\"date\">#{@content[:date].strftime("%B %e, %Y")}</h2>\n" + "<div id=\"body\">\n" + "#{@content[:body]}\n" + "</div>\n" + "</div>" _html end |
#process ⇒ Object
Pull out metadata and markup the post
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/den/post.rb', line 46 def process File.open(@file) do |f| # Extract the date post = { :id => f.readline.chomp, :date => DateTime.strptime(f.readline.chomp, "%Y-%m-%d %H:%M:%S %z") } # Process the post post.merge!(markup(f.read)) # Store the processed info @content = post end end |
#to_s ⇒ Object
7 8 9 |
# File 'lib/den/post.rb', line 7 def to_s "Post #{@content[:id]}" end |