Class: Vedeu::Views::Stream

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

Overview

Represents a character or collection of characters as part of a Line which you wish to colour and style independently of the other characters in that line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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

Parameters:

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

Options Hash (attributes):



48
49
50
51
52
53
54
# File 'lib/vedeu/models/views/stream.rb', line 48

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)


27
28
29
# File 'lib/vedeu/models/views/stream.rb', line 27

def attributes
  @attributes
end

#parentVedeu::Views::Line

Returns:



31
32
33
# File 'lib/vedeu/models/views/stream.rb', line 31

def parent
  @parent
end

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

#valueString Also known as: content, text

Returns:

  • (String)


35
36
37
# File 'lib/vedeu/models/views/stream.rb', line 35

def value
  @value
end

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:

  • (Boolean)

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

Parameters:

Returns:



58
59
60
# File 'lib/vedeu/models/views/stream.rb', line 58

def add(child)
  parent.add(child)
end

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

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

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

#charsArray

Returns an array of characters, each element is the escape sequences of colours and styles for this stream, the character itself, and the escape sequences of colours and styles for the parent of the stream (Line).

Returns:

  • (Array)


69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vedeu/models/views/stream.rb', line 69

def chars
  return [] if value.empty?

  @chars ||= value.chars.map do |char|
    member.new(value:    char,
               name:     name,
               parent:   parent,
               colour:   colour,
               style:    style,
               position: nil)
  end
end

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

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

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

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


123
124
125
126
127
128
129
130
131
# File 'lib/vedeu/models/views/stream.rb', line 123

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

#demodulize(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.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#deputy(client = nil) ⇒ Vedeu::DSL::Stream

Returns a DSL instance responsible for defining the DSL methods of this model.

Parameters:

  • client (Object|NilClass) (defaults to: nil)

    The client binding represents the client application object that is currently invoking a DSL method. It is required so that we can send messages to the client application object should we need to.

Returns:



90
91
92
# File 'lib/vedeu/models/views/stream.rb', line 90

def deputy(client = nil)
  Vedeu::DSL::Stream.new(self, client)
end

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

An object is equal when its values are the same.

Parameters:

Returns:

  • (Boolean)


98
99
100
101
102
# File 'lib/vedeu/models/views/stream.rb', line 98

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

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

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

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

#nameNilClass|String|Symbol

Returns:

  • (NilClass|String|Symbol)


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

def name
  parent.name if parent
end

#position?Boolean (private) Originally defined in module Presentation

Returns a boolean indicating the model has a position attribute.

Returns:

  • (Boolean)

#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:

  • (Boolean)

#render_colourString (private) Originally defined in module Presentation

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

Returns:

  • (String)

#render_positionString (private) Originally defined in module Presentation

Returns:

  • (String)

#render_styleString (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).

Returns:

  • (String)

#sizeFixnum

Returns the size of the content in characters without formatting.

Returns:

  • (Fixnum)


114
115
116
# File 'lib/vedeu/models/views/stream.rb', line 114

def size
  value.size
end

#snake_case(name) ⇒ 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"

Parameters:

  • name (String)

Returns:

  • (String)

#storevoid 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.

#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.