Class: Vedeu::Views::Line

Inherits:
Object
  • Object
show all
Includes:
Model, Presentation
Defined in:
lib/vedeu/models/views/line.rb

Overview

Represents a single row of the terminal. It is a container for Stream objects. A line’s width is determined by the Geometry::Geometry it belongs to.

Instance Attribute Summary collapse

Attributes included from Model

#repository

Instance Method Summary collapse

Methods included from Presentation

#render_colour, #render_position, #render_style, #to_s

Methods included from Presentation::Styles

#style, #style=

Methods included from Presentation::Colour

#background, #background=, #colour, #colour=, #foreground, #foreground=

Methods included from Model

#deputy, #dsl_class, included, #store

Methods included from Common

#demodulize, #present?, #snake_case

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Views::Line

Returns a new instance of Vedeu::Views::Line.

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):



33
34
35
36
37
38
39
# File 'lib/vedeu/models/views/line.rb', line 33

def initialize(attributes = {})
  @attributes = defaults.merge!(attributes)

  @attributes.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#attributesHash (readonly)

Returns:

  • (Hash)


19
20
21
# File 'lib/vedeu/models/views/line.rb', line 19

def attributes
  @attributes
end

#parentVedeu::Views::View

Returns:



23
24
25
# File 'lib/vedeu/models/views/line.rb', line 23

def parent
  @parent
end

Instance Method Details

#add(child) ⇒ Vedeu::Views::Stream Also known as: <<

Parameters:

Returns:



43
44
45
# File 'lib/vedeu/models/views/line.rb', line 43

def add(child)
  @value = value.add(child)
end

#charsArray

Returns an array of all the characters with formatting for this line.

Returns:

  • (Array)

See Also:



52
53
54
55
56
# File 'lib/vedeu/models/views/line.rb', line 52

def chars
  return [] if value.empty?

  @chars ||= value.flat_map(&:chars)
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


85
86
87
88
89
90
91
92
93
# File 'lib/vedeu/models/views/line.rb', line 85

def defaults
  {
    client: nil,
    colour: nil,
    parent: nil,
    style:  nil,
    value:  [],
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


62
63
64
# File 'lib/vedeu/models/views/line.rb', line 62

def eql?(other)
  self.class == other.class && value == other.value
end

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:

  • (Fixnum)


70
71
72
# File 'lib/vedeu/models/views/line.rb', line 70

def size
  value.map(&:size).inject(0, :+)
end

#valueVedeu::Views::Streams Also known as: streams



75
76
77
# File 'lib/vedeu/models/views/line.rb', line 75

def value
  collection.coerce(@value, self)
end