Class: RubyJard::Span
- Inherits:
-
Object
- Object
- RubyJard::Span
- 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
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_length ⇒ Object
Returns the value of attribute content_length.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
-
#initialize(content: '', content_length: nil, margin_left: 0, margin_right: 0, styles: []) ⇒ Span
constructor
A new instance of Span.
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
#content ⇒ Object
Returns the value of attribute content.
10 11 12 |
# File 'lib/ruby_jard/span.rb', line 10 def content @content end |
#content_length ⇒ Object
Returns the value of attribute content_length.
10 11 12 |
# File 'lib/ruby_jard/span.rb', line 10 def content_length @content_length end |
#styles ⇒ Object
Returns the value of attribute styles.
10 11 12 |
# File 'lib/ruby_jard/span.rb', line 10 def styles @styles end |