lib/signore/signature.rb in signore-0.2.4 vs lib/signore/signature.rb in signore-0.3.0

- old
+ new

@@ -1,15 +1,19 @@ require 'lovely_rufus' module Signore - Signature = Struct.new(*%i(text author source subject tags)) do - def initialize(text = '', author: nil, source: nil, subject: nil, tags: nil) - super text, author, source, subject, tags + Signature = Struct.new(*%i(author source subject tags text)) do + def initialize(author: nil, source: nil, subject: nil, tags: nil, text: nil) + super author, source, subject, tags, text each_pair { |key, value| self[key] = nil if value and value.empty? } end def tagged_with?(tag) tags and tags.include?(tag) + end + + def to_h + super.map { |key, val| [key.to_s, val] }.to_h.keep_if { |_, value| value } end def to_s spaced = text.gsub("\n", "\n\n") wrapped = LovelyRufus.wrap(spaced, width: 80)