Sha256: 6dfc55c92e2e43773bdf7d317a84231bd7d1b9f64d55e00910849955d6b1b82f
Contents?: true
Size: 899 Bytes
Versions: 2
Compression:
Stored size: 899 Bytes
Contents
module Signore Signature = Struct.new(*%i(text author source subject tags)) do class << self undef :[] end def self.[] author: nil, source: nil, subject: nil, tags: nil, text: nil new text, author, source, subject, tags end def tagged_with? tag tags and tags.include? tag end def to_s wrapped = LovelyRufus::TextWrapper.wrap text.gsub("\n", "\n\n"), width: 80 squeezed = wrapped.gsub("\n\n", "\n").chomp squeezed + meta_for(squeezed) end private def indent_size_for text indent = text_width(text) - meta.size - 2 indent < 0 ? 0 : indent end def meta stem = [author, subject].compact.join ' ' stem.empty? ? "#{source}" : [stem, source].compact.join(', ') end def meta_for text meta.empty? ? '' : "\n#{' ' * indent_size_for(text)}[#{meta}]" end def text_width text text.split("\n").map(&:size).max end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
signore-0.2.2 | lib/signore/signature.rb |
signore-0.2.1 | lib/signore/signature.rb |