Class: Styles::Line
- Inherits:
-
Object
- Object
- Styles::Line
- Defined in:
- lib/styles/line.rb
Instance Attribute Summary collapse
-
#applicable_properties ⇒ Object
Returns the value of attribute applicable_properties.
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#left ⇒ Object
Returns the value of attribute left.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#right ⇒ Object
Returns the value of attribute right.
-
#text ⇒ Object
The current content of the line, possibly already altered by processing.
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
- #content_width ⇒ Object
-
#initialize(line, properties = nil) ⇒ Line
constructor
A new instance of Line.
- #prop(property_name) ⇒ Object
- #prop?(property_name) ⇒ Boolean
-
#to_s ⇒ Object
The line’s main text content surrounded by any extra layout characters that may have been applied (margin, padding, border).
- #total_width ⇒ Object
Constructor Details
#initialize(line, properties = nil) ⇒ Line
Returns a new instance of Line.
7 8 9 10 11 12 13 14 |
# File 'lib/styles/line.rb', line 7 def initialize(line, properties=nil) @original = line @original.freeze @applicable_properties = properties @text = @original.dup @top = @right = @bottom = @left = '' end |
Instance Attribute Details
#applicable_properties ⇒ Object
Returns the value of attribute applicable_properties.
3 4 5 |
# File 'lib/styles/line.rb', line 3 def applicable_properties @applicable_properties end |
#bottom ⇒ Object
Returns the value of attribute bottom.
3 4 5 |
# File 'lib/styles/line.rb', line 3 def bottom @bottom end |
#left ⇒ Object
Returns the value of attribute left.
3 4 5 |
# File 'lib/styles/line.rb', line 3 def left @left end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
4 5 6 |
# File 'lib/styles/line.rb', line 4 def original @original end |
#right ⇒ Object
Returns the value of attribute right.
3 4 5 |
# File 'lib/styles/line.rb', line 3 def right @right end |
#text ⇒ Object
The current content of the line, possibly already altered by processing. By content we mean the line without additional layout characters (margin, padding, border) being applied around it. This does, however, include color information that may have been added.
19 20 21 |
# File 'lib/styles/line.rb', line 19 def text @text.nil? ? nil : @text.dup end |
#top ⇒ Object
Returns the value of attribute top.
3 4 5 |
# File 'lib/styles/line.rb', line 3 def top @top end |
Instance Method Details
#content_width ⇒ Object
36 37 38 |
# File 'lib/styles/line.rb', line 36 def content_width colors.uncolor(text).size end |
#prop(property_name) ⇒ Object
40 41 42 43 |
# File 'lib/styles/line.rb', line 40 def prop(property_name) prop_name = property_name.to_sym applicable_properties.find { |prop| prop.class.to_sym == prop_name } end |
#prop?(property_name) ⇒ Boolean
45 46 47 |
# File 'lib/styles/line.rb', line 45 def prop?(property_name) !!prop(property_name) end |
#to_s ⇒ Object
The line’s main text content surrounded by any extra layout characters that may have been applied (margin, padding, border). When processing is complete this represents the complete result to be written to the output stream.
26 27 28 29 30 |
# File 'lib/styles/line.rb', line 26 def to_s return '' unless text bottom_and_newline = "\n#{bottom}" if bottom && !bottom.empty? "#{top}#{left}#{text}#{right}#{bottom_and_newline}" end |
#total_width ⇒ Object
32 33 34 |
# File 'lib/styles/line.rb', line 32 def total_width colors.uncolor("#{left}#{text}#{right}").size end |