Class: Vedeu::Stream

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

Direct Known Subclasses

API::Stream

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Presentation

#colour, #style

Methods included from Coercions

included

Constructor Details

#initialize(attributes = {}, &block) ⇒ Stream

Parameters:

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


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vedeu/models/stream.rb', line 18

def initialize(attributes = {}, &block)
  @attributes = defaults.merge!(attributes)
  @align      = @attributes[:align]
  @text       = @attributes[:text]
  @width      = @attributes[:width]

  if block_given?
    @self_before_instance_eval = eval('self', block.binding)

    instance_eval(&block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

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 [].

Returns:



74
75
76
# File 'lib/vedeu/models/stream.rb', line 74

def method_missing(method, *args, &block)
  @self_before_instance_eval.send(method, *args, &block)
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



6
7
8
# File 'lib/vedeu/models/stream.rb', line 6

def align
  @align
end

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/vedeu/models/stream.rb', line 6

def attributes
  @attributes
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/vedeu/models/stream.rb', line 6

def text
  @text
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/vedeu/models/stream.rb', line 6

def width
  @width
end

Class Method Details

.build(attributes = {}, &block) ⇒ Hash

Parameters:

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

Returns:

  • (Hash)


11
12
13
# File 'lib/vedeu/models/stream.rb', line 11

def self.build(attributes = {}, &block)
  new(attributes, &block).attributes
end

Instance Method Details

#alignedString (private)

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)


46
47
48
49
50
51
52
# File 'lib/vedeu/models/stream.rb', line 46

def aligned
  case align
  when :right  then text.rjust(width,  ' ')
  when :centre then text.center(width, ' ')
  else text.ljust(width, ' ')
  end
end

#dataString (private)

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)


40
41
42
# File 'lib/vedeu/models/stream.rb', line 40

def data
  width? ? aligned : text
end

#defaultsHash (private)

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)


62
63
64
65
66
67
68
69
70
# File 'lib/vedeu/models/stream.rb', line 62

def defaults
  {
    colour: {},
    style:  [],
    text:   '',
    width:  nil,
    align:  :left
  }
end

#to_sString

Returns:

  • (String)


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

def to_s
  [ colour, style, data ].join
end

#width?TrueClass|FalseClass (private)

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:

  • (TrueClass|FalseClass)


56
57
58
# File 'lib/vedeu/models/stream.rb', line 56

def width?
  !!width
end