module Signore class Signature < Struct.new :text, :author, :source, :subject, :tags def tagged_with? tag tags and tags.include? tag end def to_s wrapped = LovelyRufus::Wrapper.new(text.gsub("\n", "\n\n")).wrapped(80).gsub("\n\n", "\n") wrapped + meta_for(wrapped) end private def meta case when author && subject && source then "#{author} #{subject}, #{source}" when author && subject then "#{author} #{subject}" when author && source then "#{author}, #{source}" when author then "#{author}" when source then "#{source}" when subject then "#{subject}" end end def meta_for wrapped return '' unless meta indent = wrapped.split("\n").map(&:size).max - meta.size - 2 spaces = indent > 0 ? ' ' * indent : '' "\n#{spaces}[#{meta}]" end end end