Class: Vedeu::Composition
- Inherits:
-
Object
- Object
- Vedeu::Composition
- Defined in:
- lib/vedeu/models/composition.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.build(attributes = {}, &block) ⇒ Hash
Builds a new composition, which is a collection of interfaces, ready to be rendered to the screen.
Instance Method Summary collapse
- #defaults ⇒ Hash private private
- #initialize(attributes = {}, &block) ⇒ Composition constructor
-
#interfaces ⇒ Array
Returns a collection of interface attributes associated with this composition.
- #method_missing(method, *args, &block) ⇒ Object private private
-
#to_s ⇒ String
Returns the complete escape sequence which this composition renders to.
Constructor Details
#initialize(attributes = {}, &block) ⇒ Composition
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
#attributes ⇒ Object (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.
12 13 14 |
# File 'lib/vedeu/models/composition.rb', line 12 def self.build(attributes = {}, &block) new(attributes, &block).attributes end |
Instance Method Details
#defaults ⇒ Hash (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.
63 64 65 66 67 |
# File 'lib/vedeu/models/composition.rb', line 63 def defaults { interfaces: [] } end |
#interfaces ⇒ Array
Returns a collection of interface attributes associated with this composition.
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_s ⇒ String
Returns the complete escape sequence which this composition renders to. This is used by Terminal#output to draw the view.
55 56 57 |
# File 'lib/vedeu/models/composition.rb', line 55 def to_s interfaces.map(&:to_s).join end |