Class: Vedeu::Composition

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/models/composition.rb

Direct Known Subclasses

API::Composition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Parameters:

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


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

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

  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.



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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/vedeu/models/composition.rb', line 4

def attributes
  @attributes
end

Class Method Details

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

Builds a new composition, which is a collection of interfaces, ready to be rendered to the screen.

Parameters:

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

Returns:

  • (Hash)


12
13
14
# File 'lib/vedeu/models/composition.rb', line 12

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

Instance Method Details

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


63
64
65
66
67
# File 'lib/vedeu/models/composition.rb', line 63

def defaults
  {
    interfaces: []
  }
end

#interfacesArray

Returns a collection of interface attributes associated with this composition.

Returns:

  • (Array)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vedeu/models/composition.rb', line 33

def interfaces
  @interfaces ||= if attributes[:interfaces].nil? || attributes[:interfaces].empty?
    []

  else
    [ attributes[:interfaces] ].flatten.map do |attrs|
      stored = Buffers.retrieve_attributes(attrs[:name])

      combined = stored.merge(attrs) do |key, s, a|
        key == :lines && s.empty? ? a : s
      end

      Interface.new(combined)
    end

  end
end

#to_sString

Returns the complete escape sequence which this composition renders to. This is used by Terminal#output to draw the view.

Returns:

  • (String)


55
56
57
# File 'lib/vedeu/models/composition.rb', line 55

def to_s
  interfaces.map(&:to_s).join
end