Class: Mantra::Transform::TemplatizeIpAddress::QuadSplitter
- Inherits:
-
Object
- Object
- Mantra::Transform::TemplatizeIpAddress::QuadSplitter
- Includes:
- Helpers::TemplateHelper
- Defined in:
- lib/mantra/transform/templatize_ip_address.rb
Overview
def templatize(parts)
raise "wrong!!!"
merged_parts = [parts.shift]
parts.each do |p|
if !p.is_a?(Scope) && !merged_parts.last.is_a?(Scope)
merged_parts.last.concat(p)
else
merged_parts << p
end
end
merged_parts.select { |p| !p.empty? }.map do |p|
p.is_a?(Scope) ? p : "\"#{p}\""
end
end
Instance Attribute Summary collapse
-
#parts(options = {templatize: false}) ⇒ Object
Returns the value of attribute parts.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(ip_address, template_quads) ⇒ QuadSplitter
constructor
A new instance of QuadSplitter.
Methods included from Helpers::TemplateHelper
Constructor Details
#initialize(ip_address, template_quads) ⇒ QuadSplitter
Returns a new instance of QuadSplitter.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/mantra/transform/templatize_ip_address.rb', line 92 def initialize(ip_address, template_quads) @values = {} = template_quads.map do |quad| quad["range_object"] = if quad["number"] index = quad["number"].to_i - 1 (index..index) elsif quad["range"] index1, index2 = *quad["range"].split("-").map { |v| v.strip.to_i - 1 } (index1..index2) end quad end template = IpAddressTemplate.new(ip_address) .each do |option| range = option["range_object"] value_to_extract = template.quads[range].join(".") if option["with_value"].nil? || value_to_extract == option["with_value"] template.replace_with_scope(range, option["scope"]) @values[option["scope"]] = value_to_extract end end @parts = template.parts end |
Instance Attribute Details
#parts(options = {templatize: false}) ⇒ Object
Returns the value of attribute parts.
91 92 93 |
# File 'lib/mantra/transform/templatize_ip_address.rb', line 91 def parts @parts end |
#values ⇒ Object
Returns the value of attribute values.
91 92 93 |
# File 'lib/mantra/transform/templatize_ip_address.rb', line 91 def values @values end |