Class: MonospaceTextFormatter::Line
- Inherits:
-
Object
- Object
- MonospaceTextFormatter::Line
- Defined in:
- lib/monospace_text_formatter/line.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
Returns the value of attribute align.
-
#fill ⇒ Object
Returns the value of attribute fill.
-
#omission ⇒ Object
Returns the value of attribute omission.
-
#padding_left ⇒ Object
Returns the value of attribute padding_left.
-
#padding_right ⇒ Object
Returns the value of attribute padding_right.
Instance Method Summary collapse
- #attributes(attrs = {}) ⇒ Object
-
#initialize(string_or_chunk, attrs = {}) ⇒ Line
constructor
A new instance of Line.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #truncated? ⇒ Boolean
- #width ⇒ Object
- #width=(fixed_width) ⇒ Object
Constructor Details
#initialize(string_or_chunk, attrs = {}) ⇒ Line
Returns a new instance of Line.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/monospace_text_formatter/line.rb', line 4 def initialize(string_or_chunk, attrs={}) @padding_left = 0 @padding_right = 0 @omission = string_to_chunk(" ...") @align = :left @fill = " " @truncated = nil raise ArgumentError, "No string given" unless string_or_chunk @original_chunk = to_chunk_if_string(string_or_chunk) attributes(attrs) end |
Instance Attribute Details
#align ⇒ Object
Returns the value of attribute align.
18 19 20 |
# File 'lib/monospace_text_formatter/line.rb', line 18 def align @align end |
#fill ⇒ Object
Returns the value of attribute fill.
18 19 20 |
# File 'lib/monospace_text_formatter/line.rb', line 18 def fill @fill end |
#omission ⇒ Object
Returns the value of attribute omission.
18 19 20 |
# File 'lib/monospace_text_formatter/line.rb', line 18 def omission @omission end |
#padding_left ⇒ Object
Returns the value of attribute padding_left.
18 19 20 |
# File 'lib/monospace_text_formatter/line.rb', line 18 def padding_left @padding_left end |
#padding_right ⇒ Object
Returns the value of attribute padding_right.
18 19 20 |
# File 'lib/monospace_text_formatter/line.rb', line 18 def padding_right @padding_right end |
Instance Method Details
#attributes(attrs = {}) ⇒ Object
24 25 26 |
# File 'lib/monospace_text_formatter/line.rb', line 24 def attributes(attrs={}) attrs.each { |name, value| send("#{name}=", value) } end |
#inspect ⇒ Object
85 86 87 |
# File 'lib/monospace_text_formatter/line.rb', line 85 def inspect %Q(#<#{self.class} #{to_s.inspect}>) end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/monospace_text_formatter/line.rb', line 81 def to_s aligned_visible_text end |
#truncated? ⇒ Boolean
76 77 78 79 |
# File 'lib/monospace_text_formatter/line.rb', line 76 def truncated? visible_chunk @truncated end |
#width ⇒ Object
20 21 22 |
# File 'lib/monospace_text_formatter/line.rb', line 20 def width @fixed_width || padding_left + visible_chunk.display_length + padding_right end |
#width=(fixed_width) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/monospace_text_formatter/line.rb', line 28 def width=(fixed_width) return if fixed_width == @fixed_width raise ArgumentError, "The :width must be equal or greater than 0, but is #{fixed_width}" unless fixed_width.nil? or fixed_width >= 0 @aligned_visible_text = @visible_chunk = @fixed_width_minus_padding = nil @fixed_width = fixed_width end |