require 'time' class FrenchPress class Post # Represents a generic post (i.e. a text post) class Generic attr_reader :file_name attr_writer :parent_blog def initialize(content, file_type = nil) title = (rand(36**9) + rand(36**10)).to_s(36) # Random title assign_variables(:@content => content, :@blog => FrenchPress.working, :@date => Time.now, :@title => title, :@file_type => file_type) derive_variables end def assign_variables(args) args.each(&method(:instance_variable_set)) # Thanks, SO end def derive_variables @file_name = @date.strftime '%Y-%m-%d' + '-' + @title @file_suffix = 'jpeg' if @file_suffix == 'jpg' @file_suffix ||= 'html' end def tags [ '---', "type: #{@type}", "date: #{@date.strftime '%Y-%m-%d %H:%M:%S'}", 'layout: post', "title: #{@title}", '---' ] end def render @content end def render_as_quote "" \ "#{@parent_blog[:host]}\n" \ "
#{render}" end def render_with_tags (tags << render).join("\n") end end end end