class Creq::Writer
Public Class Methods
call(req, stream = $stdout)
click to toggle source
# File lib/creq/writer.rb, line 7 def self.call(req, stream = $stdout) writer = new(req.root) writer.write(req, stream) end
new(root)
click to toggle source
# File lib/creq/writer.rb, line 23 def initialize(root) @root = root end
Public Instance Methods
text(r)
click to toggle source
# File lib/creq/writer.rb, line 16 def text(r) [title(r), attributes(r), body(r)] .select{|i| !i.empty?}.join("\n") end
write(req, stream)
click to toggle source
# File lib/creq/writer.rb, line 12 def write(req, stream) stream.puts req.map{|r| text(r)}.join("\n\n") end
Protected Instance Methods
attributes(r)
click to toggle source
# File lib/creq/writer.rb, line 31 def attributes(r) return "" if r.user_attributes.empty? t = ["{{"] r.user_attributes.inject(t){|s, (k, v)| s << "#{k}: #{v}"} t << "}}" t.join("\n") end
body(r)
click to toggle source
# File lib/creq/writer.rb, line 39 def body(r) return "\n" << r.body unless r.body.empty? r.body end
title(r)
click to toggle source
# File lib/creq/writer.rb, line 27 def title(r) "#{'#' * r.level} [#{r.id}] #{r.title}" end