Class: Vedeu::API::Line

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/vedeu/api/line.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#colour, #style

Constructor Details

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



10
11
12
13
14
15
# File 'lib/vedeu/api/line.rb', line 10

def initialize(attributes = {}, &block)
  @attributes                = attributes
  @self_before_instance_eval = eval('self', block.binding)

  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Class Method Details

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



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

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

Instance Method Details

#attributesObject



41
42
43
# File 'lib/vedeu/api/line.rb', line 41

def attributes
  @_attributes ||= defaults.merge!(@attributes)
end

#background(value = '', &block) ⇒ Object



35
36
37
38
39
# File 'lib/vedeu/api/line.rb', line 35

def background(value = '', &block)
  attributes[:streams] << API::Stream.build({
                            colour: { background: value }
                          }, &block)
end

#buildObject



17
18
19
# File 'lib/vedeu/api/line.rb', line 17

def build
  attributes
end

#defaultsObject



45
46
47
48
49
50
51
# File 'lib/vedeu/api/line.rb', line 45

def defaults
  {
    colour:  {},
    style:   [],
    streams: []
  }
end

#foreground(value = '', &block) ⇒ Object



29
30
31
32
33
# File 'lib/vedeu/api/line.rb', line 29

def foreground(value = '', &block)
  attributes[:streams] << API::Stream.build({
                            colour: { foreground: value }
                          }, &block)
end

#stream(&block) ⇒ Object



21
22
23
# File 'lib/vedeu/api/line.rb', line 21

def stream(&block)
  attributes[:streams] << API::Stream.build(&block)
end

#text(value) ⇒ Object



25
26
27
# File 'lib/vedeu/api/line.rb', line 25

def text(value)
  attributes[:streams] << { text: value }
end