Class: Vedeu::Views::Line

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Presentation, Repositories::Model, DefaultAttributes, Value
Defined in:
lib/vedeu/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 Geometries::Geometry it belongs to.

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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

Parameters:

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

Options Hash (attributes):



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

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#alignVedeu::Coercers::Alignment (readonly) Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

#padString (readonly) Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

#repositoryVedeu::Repositories::Repository Originally defined in module Repositories::Model

#truncateBoolean (readonly) Also known as: truncate? Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

#widthFixnum|NilClass (readonly) Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum|NilClass)

#wordwrapBoolean (readonly) Also known as: wordwrap? Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

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

Parameters:

Returns:



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

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

#attributesHash<Symbol => void> Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol => void>)

#backgroundVedeu::Colours::Background Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

When the background colour for the model exists, return it, otherwise returns the parent background colour, or an empty Vedeu::Colours::Background.

#background=(value) ⇒ Vedeu::Colours::Background Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Allows the setting of the background colour by coercing the given value into a Vedeu::Colours::Background colour.

#become(klass, attributes) ⇒ Class Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#charsArray

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

Returns:

  • (Array)

See Also:



71
72
73
74
75
# File 'lib/vedeu/views/line.rb', line 71

def chars
  return [] unless streams?

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

#colourVedeu::Colours::Colour Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

#colour=(value) ⇒ Vedeu::Colours::Colour Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Allows the setting of the model’s colour by coercing the given value into a Vedeu::Colours::Colour.

#colour?Boolean Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

#defaultsHash<Symbol => Array<void>|NilClass> (private) Originally defined in module DefaultAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The default values for a new instance of this class.

Returns:

  • (Hash<Symbol => Array<void>|NilClass>)

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

An object is equal when its values are the same.

Parameters:

Returns:



81
82
83
# File 'lib/vedeu/views/line.rb', line 81

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

#escape?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#foregroundVedeu::Colours::Foreground Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

When the foreground colour for the model exists, return it, otherwise returns the parent foreground colour, or an empty Vedeu::Colours::Foreground.

#foreground=(value) ⇒ Vedeu::Colours::Foreground Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Allows the setting of the foreground colour by coercing the given value into a Vedeu::Colours::Foreground colour.

#hash?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#line_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Line.

Returns:

#nameNilClass|String|Symbol

Returns:

  • (NilClass|String|Symbol)


87
88
89
90
91
92
93
94
95
# File 'lib/vedeu/views/line.rb', line 87

def name
  if present?(@name)
    @name

  elsif parent && present?(parent.name)
    parent.name

  end
end

#named_colourVedeu::Colours::Colour (private) Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

#named_colour?Boolean (private) Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

#numeric?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#parentNilClass|void

Returns:

  • (NilClass|void)


98
99
100
# File 'lib/vedeu/views/line.rb', line 98

def parent
  present?(@parent) ? @parent : nil
end

#parent_colourVedeu::Colours::Colour (private) Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

#parent_colour?Boolean (private) Originally defined in module Presentation::Colour

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

#positionVedeu::Geometries::Position Originally defined in module Presentation::Position

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the position.

#position=(value) ⇒ Vedeu::Geometries::Position Originally defined in module Presentation::Position

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the position.

Parameters:

Returns:

#position?Boolean Originally defined in module Presentation::Position

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the position attribute of the including model is set.

Returns:

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#render_colour(&block) ⇒ String (private) Originally defined in module Presentation

Renders the colour attributes of the receiver and yields (to then render the styles).

Parameters:

  • block (Proc)

Returns:

  • (String)

#render_position(&block) ⇒ String (private) Originally defined in module Presentation

Parameters:

  • block (Proc)

Returns:

  • (String)

#render_style(&block) ⇒ String (private) Originally defined in module Presentation

Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).

Parameters:

  • block (Proc)

Returns:

  • (String)

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:

  • (Fixnum)


106
107
108
# File 'lib/vedeu/views/line.rb', line 106

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

#snake_case(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#store(&block) ⇒ void Originally defined in module Repositories::Model

TODO:

Perhaps some validation could be added here?

Note:

If a block is given, store the model, return the model after yielding.

This method returns an undefined value.

Returns The model instance stored in the repository.

#stream_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#styleVedeu::Presentation::Style Originally defined in module Presentation::Styles

When the style for the model exists, return it, otherwise returns the parent style, or an empty Vedeu::Presentation::Style.

#style=(value) ⇒ Vedeu::Presentation::Style Originally defined in module Presentation::Styles

Allows the setting of the style by coercing the given value into a Vedeu::Presentation::Style.

#to_sString Also known as: to_str Originally defined in module Presentation

Converts the colours and styles to escape sequences, and when the parent model has previously set the colour and style, reverts back to that for consistent formatting.

Returns:

  • (String)

    An escape sequence with value interpolated.

#truthy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#validate(attributes) ⇒ Hash (private) Originally defined in module Repositories::Defaults

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • attributes (Hash)

Returns:

  • (Hash)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.

#view_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::View.

Returns:

#xFixnum|NilClass Originally defined in module Presentation::Position

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the x coordinate for the model when the position attribute of the including model is set.

Returns:

  • (Fixnum|NilClass)

#yFixnum|NilClass Originally defined in module Presentation::Position

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the y coordinate for the model when the position attribute of the including model is set.

Returns:

  • (Fixnum|NilClass)