Class: IpAddressTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/mantra/helpers/template_helper.rb

Defined Under Namespace

Classes: Scope, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_address) ⇒ IpAddressTemplate

Returns a new instance of IpAddressTemplate.



21
22
23
# File 'lib/mantra/helpers/template_helper.rb', line 21

def initialize(ip_address)
  @quads = ip_address.split(".").map { |q| Value.new(q) }
end

Instance Attribute Details

#quadsObject

Returns the value of attribute quads.



20
21
22
# File 'lib/mantra/helpers/template_helper.rb', line 20

def quads
  @quads
end

Instance Method Details

#partsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mantra/helpers/template_helper.rb', line 33

def parts
  result = [@quads.first]
  @quads[1..-1].each do |q|
    if q.is_scope? && result.last.is_scope? && q.scope == result.last.scope
      result.last.value = [result.last.value, q.value].join(".")
    else
      result << Value.new(".") << q
    end
  end
  result
end

#replace_with_scope(range, scope) ⇒ Object Also known as: replace_quad_range_with_scope



25
26
27
28
29
# File 'lib/mantra/helpers/template_helper.rb', line 25

def replace_with_scope(range, scope)
  range.to_a.each do |i|
    @quads[i] = Scope.new(scope: scope, value: @quads[i])
  end
end