Class: IpAddressTemplate
- Inherits:
-
Object
- Object
- IpAddressTemplate
- Defined in:
- lib/mantra/helpers/template_helper.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#quads ⇒ Object
Returns the value of attribute quads.
Instance Method Summary collapse
-
#initialize(ip_address) ⇒ IpAddressTemplate
constructor
A new instance of IpAddressTemplate.
- #parts ⇒ Object
- #replace_with_scope(range, scope) ⇒ Object (also: #replace_quad_range_with_scope)
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
#quads ⇒ Object
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
#parts ⇒ Object
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 |