Class: Text
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(components) ⇒ Text
constructor
A new instance of Text.
- #truncate_to_width(width) ⇒ Object
Constructor Details
#initialize(components) ⇒ Text
Returns a new instance of Text.
665 666 667 |
# File 'lib/selecta.rb', line 665 def initialize(components) @components = components end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
654 655 656 |
# File 'lib/selecta.rb', line 654 def components @components end |
Class Method Details
Instance Method Details
#+(other) ⇒ Object
673 674 675 |
# File 'lib/selecta.rb', line 673 def +(other) Text[*(components + other.components)] end |
#==(other) ⇒ Object
669 670 671 |
# File 'lib/selecta.rb', line 669 def ==(other) components == other.components end |
#truncate_to_width(width) ⇒ Object
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/selecta.rb', line 677 def truncate_to_width(width) chars_remaining = width # Truncate each string to the number of characters left within our # allowed width. Leave anything else alone. This may result in empty # strings and unused ANSI control codes in the output, but that's fine. components = self.components.map do |component| if component.is_a?(String) component = component[0, chars_remaining] chars_remaining -= component.length end component end Text.new(components) end |