class Proxy::DHCP::Infoblox::RangeRegularExpressionGenerator::Node

Attributes

children[RW]
value[RW]

Public Class Methods

new(value, children = []) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb, line 8
def initialize(value, children = [])
  @value = value
  @children = children
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb, line 19
def <=>(other)
  return -1 if value.to_s == '0?'
  return 1 if other.value.to_s == '0?'
  return 0 if value == other.value
  return -1 if value < other.value
  1
end
add_child(a_node) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb, line 27
def add_child(a_node)
  children.push(a_node)
  children.sort!
  a_node
end
add_children(values) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb, line 13
def add_children(values)
  return if values.empty?
  node = (found = children.find { |n| n.value == values.first }).nil? ? add_child(Node.new(values.first)) : found
  node.add_children(values[1..-1])
end
as_regex() click to toggle source
# File lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb, line 43
def as_regex
  children.empty? ? [value.to_s] : children.map { |c| c.as_regex.map { |r| value.to_s + r } }.flatten
end
group_children() click to toggle source
# File lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb, line 33
def group_children
  children.each { |n| n.group_children }
  return if children.size < 2
  @children = children[1..-1].each_with_object([MergedNode.new(children.first)]) do |to_group, grouped|
    current = MergedNode.new(to_group)
    found = grouped.find { |g| ((g.value != ['0?'] && current.value != ['0?']) || (current.value == ['0?'] && g.value == ['0?'])) && (g.children == current.children) }
    found.nil? ? grouped.push(current) : found.merge(current)
  end
end