Class: Styles::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/styles/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_propertiesObject

Returns the value of attribute applicable_properties.



3
4
5
# File 'lib/styles/line.rb', line 3

def applicable_properties
  @applicable_properties
end

#bottomObject

Returns the value of attribute bottom.



3
4
5
# File 'lib/styles/line.rb', line 3

def bottom
  @bottom
end

#leftObject

Returns the value of attribute left.



3
4
5
# File 'lib/styles/line.rb', line 3

def left
  @left
end

#originalObject (readonly)

Returns the value of attribute original.



4
5
6
# File 'lib/styles/line.rb', line 4

def original
  @original
end

#rightObject

Returns the value of attribute right.



3
4
5
# File 'lib/styles/line.rb', line 3

def right
  @right
end

#textObject

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

#topObject

Returns the value of attribute top.



3
4
5
# File 'lib/styles/line.rb', line 3

def top
  @top
end

Instance Method Details

#content_widthObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/styles/line.rb', line 45

def prop?(property_name)
  !!prop(property_name)
end

#to_sObject

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_widthObject



32
33
34
# File 'lib/styles/line.rb', line 32

def total_width
  colors.uncolor("#{left}#{text}#{right}").size
end