Sha256: da237795eaa187f280a70633d2544f09fde71bd9bf7f1c7926ee87ee9bd72d88

Contents?: true

Size: 718 Bytes

Versions: 11

Compression:

Stored size: 718 Bytes

Contents

module CutePrint
  # @api private
  class OutlineLabeler

    def self.label(formatter, width, label, value)
      new(formatter, width, label, value).labeled
    end

    def initialize(formatter, width, label, value)
      @formatter = formatter
      @width = width
      @label = label
      @value = value
    end

    def labeled
      [labeled_first_line] + indented_remaining_lines
    end

    private

    def labeled_first_line
      @label + lines.first
    end

    def indented_remaining_lines
      indent = ' ' * @label.size
      lines.to_a[1..-1].map do |line|
        indent + line
      end
    end

    def lines
      @lines ||= @formatter.format(@width - @label.size, @value)
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cute_print-1.4.0 lib/cute_print/outline_labeler.rb
cute_print-1.3.0 lib/cute_print/outline_labeler.rb
cute_print-1.2.0 lib/cute_print/outline_labeler.rb
cute_print-1.1.4 lib/cute_print/outline_labeler.rb
cute_print-1.1.3 lib/cute_print/outline_labeler.rb
cute_print-1.1.2 lib/cute_print/outline_labeler.rb
cute_print-1.1.1 lib/cute_print/outline_labeler.rb
cute_print-1.1.0 lib/cute_print/outline_labeler.rb
cute_print-1.0.1 lib/cute_print/outline_labeler.rb
cute_print-1.0.0 lib/cute_print/outline_labeler.rb
cute_print-0.4.0 lib/cute_print/outline_labeler.rb