Class: EasyType::NodeGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_type/node_group.rb

Overview

Simple wrapper arround a node group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(classifier, data) ⇒ NodeGroup

Returns a new instance of NodeGroup.



10
11
12
13
14
15
16
# File 'lib/easy_type/node_group.rb', line 10

def initialize(classifier, data)
  @@pdb ||= EasyType::Pdb.new
  @@all_groups ||= [] 
  @data = data
  @classifier = classifier
  @@all_groups << self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

Raises:

  • (NoMethodError)


24
25
26
27
28
# File 'lib/easy_type/node_group.rb', line 24

def method_missing(method)
  str = method.id2name
  raise NoMethodError.new("undefined method `#{method}' for #{name}:EasyType::NodeGroup") if @data[str].nil?
  @data[str]
end

Instance Attribute Details

#parent_nameObject (readonly)

Returns the value of attribute parent_name.



7
8
9
# File 'lib/easy_type/node_group.rb', line 7

def parent_name
  @parent_name
end

Instance Method Details

#em_groupObject

The top level group containin all licensed nodes



20
21
22
# File 'lib/easy_type/node_group.rb', line 20

def em_group
  'EM licensed nodes'
end

#em_group?Boolean

Returns:

  • (Boolean)


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

def em_group?
  full_name.include?(em_group)
end

#full_nameObject



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

def full_name
  value = [name]
  current_group = self
  while true do
    parent_group = @@all_groups.find {|g| g.id == current_group.parent }
    break if current_group.id == parent_group.id
    value << parent_group.name
    current_group = parent_group
  end
  "/#{value.reverse.join('/')}"
end

#matching_nodesObject



46
47
48
49
50
51
52
53
# File 'lib/easy_type/node_group.rb', line 46

def matching_nodes
  if @data['rule']
    pdb_query = @classifier.rule_to_pdb_query(@data['rule'])
    @@pdb.nodes(pdb_query['query'])
  else
    []
  end
end