lib/signore/signature.rb in signore-0.1.0 vs lib/signore/signature.rb in signore-0.1.1
- old
+ new
@@ -3,19 +3,12 @@
def tagged_with? tag
tags and tags.include? tag
end
def to_s
- lines = text.split("\n").map { |line| LovelyRufus::Wrapper.new(line).wrapped 80 }
-
- if meta
- lines << "[#{meta}]"
- max = lines.map { |line| line.split "\n" }.flatten.map(&:size).max
- lines.last.insert 0, ' ' * (max - meta.size - 2)
- end
-
- lines.join "\n"
+ wrapped = LovelyRufus::Wrapper.new(text.gsub("\n", "\n\n")).wrapped(80).gsub("\n\n", "\n")
+ wrapped + meta_for(wrapped)
end
private
def meta
@@ -25,8 +18,17 @@
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