Sha256: 1d056f6f0ef9617905e1b5cce032348b7287dd1893fead568baf29508aa7f89f

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

# frozen_string_literal: true

module RubyJard
  ##
  # Smallest unit of texts. A span includes content, margin, and styles of a particular
  # text chunk. All decorators and presenters return single/a list of spans.
  class Span
    extend Forwardable

    attr_accessor :content, :content_length, :styles

    def initialize(content: '', content_length: nil, margin_left: 0, margin_right: 0, styles: [])
      if !content.nil? && !content.empty?
        content = ' ' * margin_left + content if margin_left > 0
        content += ' ' * margin_right if margin_right > 0
      end

      @content = content.to_s.gsub(/\r\n/, '\n').gsub(/\n/, '\n')
      @content_length = content_length || @content.length
      @styles = styles
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_jard-0.3.1 lib/ruby_jard/span.rb