Module: Indicator

Defined in:
lib/indicator.rb,
lib/indicator/base.rb,
lib/indicator/mixin.rb,
lib/indicator/version.rb,
lib/indicator/auto_gen.rb,
lib/indicator/data_mapper.rb

Defined Under Namespace

Modules: AutoGen, DataMapper, Mixin Classes: Base, UnknownIndicator

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.contains?(name) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/indicator.rb', line 11

def self.contains? name
  not Indicator.get(name).nil? 
end

.create(type, *args) ⇒ Object

Raises:



23
24
25
26
27
28
# File 'lib/indicator.rb', line 23

def self.create type, *args
  klass = Indicator.get type
  raise UnknownIndicator,type if klass.nil?

  klass.send(:new, *args)  
end

.create_named(name, *args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/indicator.rb', line 30

def self.create_named name, *args
  sp = name.to_s.split "_"

  type = sp.first.to_sym

  args = sp.drop(1).collect { |a| a.to_i } if args.empty?

  obj = Indicator.create type, *args 
  obj.name = name
  obj
end

.get(name) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/indicator.rb', line 15

def self.get name
  name = name.to_s
  Base.indicators.find do |klass|
    klass_name = klass.name.split('::')[-1]
    klass_name.casecmp(name) == 0
  end
end

.info(type) ⇒ Object

Raises:



46
47
48
49
50
51
52
53
54
55
# File 'lib/indicator.rb', line 46

def self.info type
  klass = Indicator.get type
  raise UnknownIndicator,type if klass.nil?
  """Indicator: #{klass.name}
Arguments: #{klass.arguments}  
Input Count: #{klass.inputs.count}
Inputs: #{klass.inputs}
Output Count: #{klass.outputs.count}
Outputs: #{klass.outputs}"""
end

.listObject



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

def self.list
  Indicator::Base.indicators
end