Class: RubyJard::Span

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby_jard/span.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: '', content_length: nil, margin_left: 0, margin_right: 0, styles: []) ⇒ Span

Returns a new instance of Span.



12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby_jard/span.rb', line 12

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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



10
11
12
# File 'lib/ruby_jard/span.rb', line 10

def content
  @content
end

#content_lengthObject

Returns the value of attribute content_length.



10
11
12
# File 'lib/ruby_jard/span.rb', line 10

def content_length
  @content_length
end

#stylesObject

Returns the value of attribute styles.



10
11
12
# File 'lib/ruby_jard/span.rb', line 10

def styles
  @styles
end