Module: Plotrb::Kernel

Included in:
Object, Visualization
Defined in:
lib/plotrb/kernel.rb

Overview

Kernel module includes most of the shortcuts used in Plotrb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/plotrb/kernel.rb', line 82

def method_missing(method, *args, &block)
  case method.to_s
    when /^(\w)_axis$/
      # Initialize ::Plotrb::Axis objects
      if ::Plotrb::Axis::TYPES.include?($1.to_sym)
        cache_method($1, 'axis')
        self.send(method)
      else
        super
      end
    when /^(\w+)_scale$/
      # Initialize ::Plotrb::Scale objects
      if ::Plotrb::Scale::TYPES.include?($1.to_sym)
        cache_method($1, 'scale')
        self.send(method)
      else
        super
      end
    when /^(\w+)_transform$/
      # Initialize ::Plotrb::Transform objects
      if ::Plotrb::Transform::TYPES.include?($1.to_sym)
        cache_method($1, 'transform')
        self.send(method)
      else
        super
      end
    when /^(\w+)_mark$/
      # Initialize ::Plotrb::Mark objects
      if ::Plotrb::Mark::TYPES.include?($1.to_sym)
        cache_method($1, 'mark')
        self.send(method)
      else
        super
      end
    else
      super
  end
end

Class Method Details

.axesObject

a global space keeping track of all Axis objects defined



22
23
24
# File 'lib/plotrb/kernel.rb', line 22

def self.axes
  @axes ||= []
end

.dataObject

a global space keeping track of all Data objects defined



7
8
9
# File 'lib/plotrb/kernel.rb', line 7

def self.data
  @data ||= []
end

.duplicate_data?(name) ⇒ Boolean

Returns if a Data object with same name already exists.

Returns:

  • (Boolean)

    if a Data object with same name already exists



17
18
19
# File 'lib/plotrb/kernel.rb', line 17

def self.duplicate_data?(name)
  @data.select { |d| d.name == name.to_s }.size > 1
end

.duplicate_mark?(name) ⇒ Boolean

Returns if a Mark object with same name already exists.

Returns:

  • (Boolean)

    if a Mark object with same name already exists



52
53
54
# File 'lib/plotrb/kernel.rb', line 52

def self.duplicate_mark?(name)
  @marks.select { |m| m.name == name.to_s }.size > 1
end

.duplicate_scale?(name) ⇒ Boolean

Returns if a Scale object with same name already exists.

Returns:

  • (Boolean)

    if a Scale object with same name already exists



37
38
39
# File 'lib/plotrb/kernel.rb', line 37

def self.duplicate_scale?(name)
  @scales.select { |s| s.name == name.to_s }.size > 1
end

.find_data(name) ⇒ Data

Returns find Data object by name.

Returns:

  • (Data)

    find Data object by name



12
13
14
# File 'lib/plotrb/kernel.rb', line 12

def self.find_data(name)
  @data.find { |d| d.name == name.to_s }
end

.find_mark(name) ⇒ Mark

Returns find Mark object by name.

Returns:

  • (Mark)

    find Mark object by name



47
48
49
# File 'lib/plotrb/kernel.rb', line 47

def self.find_mark(name)
  @marks.find { |m| m.name == name.to_s }
end

.find_scale(name) ⇒ Scale

Returns find Scale object by name.

Returns:

  • (Scale)

    find Scale object by name



32
33
34
# File 'lib/plotrb/kernel.rb', line 32

def self.find_scale(name)
  @scales.find { |s| s.name == name.to_s }
end

.legendsObject

a global space keeping track of all Transform objects defined



62
63
64
# File 'lib/plotrb/kernel.rb', line 62

def self.legends
  @legends ||= []
end

.marksObject

a global space keeping track of all Mark objects defined



42
43
44
# File 'lib/plotrb/kernel.rb', line 42

def self.marks
  @marks ||= []
end

.scalesObject

a global space keeping track of all Scale objects defined



27
28
29
# File 'lib/plotrb/kernel.rb', line 27

def self.scales
  @scales ||= []
end

.transformsObject

a global space keeping track of all Transform objects defined



57
58
59
# File 'lib/plotrb/kernel.rb', line 57

def self.transforms
  @transforms ||= []
end

Instance Method Details

#legend(&block) ⇒ Object



78
79
80
# File 'lib/plotrb/kernel.rb', line 78

def legend(&block)
	  ::Plotrb::Legend.new(&block)
end

#pdata(&block) ⇒ Object

Initialize ::Plotrb::Data objects



74
75
76
# File 'lib/plotrb/kernel.rb', line 74

def pdata(&block)
  ::Plotrb::Data.new(&block)
end

#visualization(&block) ⇒ Object

Initialize ::Plotrb::Visualization object



68
69
70
# File 'lib/plotrb/kernel.rb', line 68

def visualization(&block)
  ::Plotrb::Visualization.new(&block)
end