Class: ODDB::AtcNode

Inherits:
Object show all
Defined in:
src/model/atcnode.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AtcNode) initialize(atcclass)

A new instance of AtcNode



7
8
9
10
# File 'src/model/atcnode.rb', line 7

def initialize(atcclass)
  @atc_class = atcclass
  @children = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(*args)



18
19
20
# File 'src/model/atcnode.rb', line 18

def method_missing(*args)
  @atc_class.send(*args) unless @atc_class.nil?
end

Instance Attribute Details

- (Object) children (readonly)

Returns the value of attribute children



6
7
8
# File 'src/model/atcnode.rb', line 6

def children
  @children
end

Instance Method Details

- (Object) add_offspring(atc_node)



21
22
23
24
25
26
27
28
29
30
# File 'src/model/atcnode.rb', line 21

def add_offspring(atc_node)
  nextnode = @children.select { |node| 
    node.path_to?(atc_node.code) 
  }.first
  unless(nextnode.nil?)
    nextnode.add_offspring(atc_node)
  else
    @children.push(atc_node)
  end
end

- (Object) delete(atc_code)



31
32
33
34
35
36
# File 'src/model/atcnode.rb', line 31

def delete(atc_code)
  @children.delete_if { |node| node.code == atc_code }
  @children.each { |node| 
    node.delete(atc_code) if node.path_to?(atc_code)
  }
end

- (Object) each(&block)



37
38
39
40
# File 'src/model/atcnode.rb', line 37

def each(&block)
  block.call(self)
  children.each(&block)
end

- (Boolean) has_sequence?

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'src/model/atcnode.rb', line 41

def has_sequence?
  (!@atc_class.nil? && !@atc_class.sequences.empty?) \
  || @children.any? { |node|
    node.has_sequence?  
  }
end

- (Object) level



47
48
49
50
# File 'src/model/atcnode.rb', line 47

def level
  return 0 if @atc_class.nil?
  @atc_class.level
end

- (Object) method(name)



11
12
13
14
15
16
17
# File 'src/model/atcnode.rb', line 11

def method(name)
  begin
    super
  rescue NameError
    @atc_class.method(name)
  end
end

- (Boolean) path_to?(atccode)

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
# File 'src/model/atcnode.rb', line 51

def path_to?(atccode)
  return true if @atc_class.nil?
  return false if atccode.nil?
  cd = @atc_class.code
  begin
    atccode.length >= cd.length \
      && cd == atccode[0,cd.length]
  rescue
  end
end