Class: Vedeu::Char

Inherits:
Object
  • Object
show all
Includes:
Presentation
Defined in:
lib/vedeu/models/view/char.rb

Overview

A Char represents a single character of the terminal. It is a container for the a single character in a Stream.

Though a multi-character String can be passed as a value, only the first character is returned in the escape sequence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Presentation

#background, #colour, #colour=, #foreground, #parent_background, #parent_colour, #parent_foreground, #parent_style, #render_border, #render_colour, #render_position, #render_style, #style, #style=, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ Char

Returns a new instance of Char.

Parameters:

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

Options Hash (attributes):



31
32
33
34
35
36
37
38
39
# File 'lib/vedeu/models/view/char.rb', line 31

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

  @border   = @attributes[:border]
  @colour   = @attributes[:colour]
  @parent   = @attributes[:parent]
  @style    = @attributes[:style]
  @value    = @attributes[:value]
end

Instance Attribute Details

#attributesObject (readonly, private)

Returns the value of attribute attributes.



81
82
83
# File 'lib/vedeu/models/view/char.rb', line 81

def attributes
  @attributes
end

#borderObject

Returns the value of attribute border.



16
17
18
# File 'lib/vedeu/models/view/char.rb', line 16

def border
  @border
end

#parentObject

Returns the value of attribute parent.



16
17
18
# File 'lib/vedeu/models/view/char.rb', line 16

def parent
  @parent
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other

Returns:

  • (Boolean)


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

def ==(other)
  eql?(other)
end

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


86
87
88
89
90
91
92
93
94
95
# File 'lib/vedeu/models/view/char.rb', line 86

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

#eql?(other) ⇒ Boolean

Parameters:

  • other

Returns:

  • (Boolean)


49
50
51
# File 'lib/vedeu/models/view/char.rb', line 49

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

#positionVedeu::Position

Returns:



54
55
56
# File 'lib/vedeu/models/view/char.rb', line 54

def position
  @position ||= Vedeu::Position.coerce(attributes[:position])
end

#position=(value) ⇒ Vedeu::Position

Parameters:

Returns:



60
61
62
# File 'lib/vedeu/models/view/char.rb', line 60

def position=(value)
  @position = Vedeu::Position.coerce(value)
end

#to_htmlString

Returns:

  • (String)


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

def to_html
  @to_html ||= HTMLChar.render(self)
end

#xFixnum|NilClass

Returns:



65
66
67
# File 'lib/vedeu/models/view/char.rb', line 65

def x
  position.x if position
end

#yFixnum|NilClass

Returns:



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

def y
  position.y if position
end