Class: Vedeu::Line
- Inherits:
-
Object
- Object
- Vedeu::Line
- Includes:
- Model, Presentation
- Defined in:
- lib/vedeu/models/line.rb
Overview
Instance Attribute Summary collapse
Attributes included from Model
Instance Method Summary collapse
- #add(child) ⇒ void
-
#chars ⇒ Array
Returns an array of all the characters with formatting for this line.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#empty? ⇒ Boolean
Returns a boolean indicating whether the line has content.
-
#initialize(attributes = {}) ⇒ Vedeu::Line
constructor
Returns a new instance of Vedeu::Line.
- #name ⇒ NilClass|String
-
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
- #value ⇒ Streams
-
#width ⇒ Fixnum
Delegate to Vedeu::Interface#width if available.
Methods included from Presentation
#_colour, #_style, #background, #background=, #colour, #colour=, #foreground, #foreground=, #parent_background, #parent_colour, #parent_foreground, #parent_style, #render_colour, #render_position, #render_style, #style, #style=, #to_s
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Line
Returns a new instance of Vedeu::Line.
35 36 37 38 39 |
# File 'lib/vedeu/models/line.rb', line 35 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @parent = @attributes[:parent] @streams = @attributes[:streams] end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
25 26 27 |
# File 'lib/vedeu/models/line.rb', line 25 def attributes @attributes end |
#streams ⇒ Vedeu::Streams
20 21 22 |
# File 'lib/vedeu/models/line.rb', line 20 def streams @streams end |
Instance Method Details
#add(child) ⇒ void
This method returns an undefined value.
43 44 45 |
# File 'lib/vedeu/models/line.rb', line 43 def add(child) @streams = streams.add(child) end |
#chars ⇒ Array
Returns an array of all the characters with formatting for this line.
51 52 53 54 55 |
# File 'lib/vedeu/models/line.rb', line 51 def chars return [] if empty? streams.flat_map(&:chars) end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
93 94 95 96 97 98 99 100 101 |
# File 'lib/vedeu/models/line.rb', line 93 def defaults { client: nil, colour: nil, parent: nil, streams: [], style: nil, } end |
#empty? ⇒ Boolean
Returns a boolean indicating whether the line has content.
60 61 62 |
# File 'lib/vedeu/models/line.rb', line 60 def empty? streams.empty? end |
#name ⇒ NilClass|String
65 66 67 |
# File 'lib/vedeu/models/line.rb', line 65 def name parent.name if parent end |
#size ⇒ Fixnum
Returns the size of the content in characters without formatting.
72 73 74 |
# File 'lib/vedeu/models/line.rb', line 72 def size streams.map(&:size).inject(0, :+) end |
#width ⇒ Fixnum
Delegate to Vedeu::Interface#width if available.
84 85 86 |
# File 'lib/vedeu/models/line.rb', line 84 def width parent.width if parent end |