Sha256: ac6047a46ed4f5bd39e43838edab3c137307a72d90221dae425eb5ab20aee328

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

module Signore class Signature < Struct.new :text, :author, :source, :subject, :tags

  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"
  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

end end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signore-0.1.0 lib/signore/signature.rb