Class: Construqt::Flavour::Ciscian::NestedSection

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/flavour/ciscian/ciscian.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section) ⇒ NestedSection

Returns a new instance of NestedSection.



181
182
183
184
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 181

def initialize(section)
  self.sections={}
  self.section=section
end

Instance Attribute Details

#sectionObject

Returns the value of attribute section.



180
181
182
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 180

def section
  @section
end

#sectionsObject

Returns the value of attribute sections.



180
181
182
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 180

def sections
  @sections
end

Class Method Details

.compare(nu, old) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 258

def self.compare(nu, old)
  return [nu] unless old
  return [old.no] unless nu
  throw "classes must match #{nu.class.name} != #{old.class.name}" unless nu.class == old.class
  if (nu.serialize==old.serialize)
    return [nil]
  else
    if (nu.no?)
      return [nu]
    else
      delta = nu.class.new(nu.section)
      (nu.sections.keys + old.sections.keys).sort.each do |k,v|
        nu_section=nu.sections[k]
        old_section=old.sections[k]
        comps = (nu_section||old_section).class.compare(nu_section, old_section)
        throw "class #{(nu_section||old_section).class.name} returns illegal nil in compare method" unless comps
        comps.compact.each do |comp|
          delta.sections[comp.section] = comp
        end
      end

      return [delta]
    end
  end
end

.parse_line(line, lines, section, result) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 195

def self.parse_line(line, lines, section, result)
  #binding.pry if line.start_with?("interface")
  if [/^\s*(no\s+|)interface/, /^\s*(no\s+|)vlan/].find{|i| line.to_s.match(i) }
    resultline=Result::Lines::Line.new(result.dialect.clear_interface(line), line.nr)
    section.add(resultline.to_s) do |_section|
      while _line = lines.shift
        break if result.dialect.block_end?(_line.to_s)
        result.parse_line(_line, lines, _section, result)
      end
    end

    if (matchdata = line.to_s.match(Construqt::Util::PORTS_DEF_REGEXP))
      ports = Construqt::Util::expandRangeDefinition(matchdata[0])
      if (ports.length>1)
        section_to_split=section.sections.delete(resultline.to_s)
        ports.each do |port|
          section.add(line.to_s.gsub(/#{Construqt::Util::PORTS_DEF_REGEXP}/, port)) do |_section|
            _section.sections.merge!(section_to_split.sections)
          end
        end
      end
    end

    return true
  end
end

Instance Method Details

#add(verb, clazz = MultiValueVerb) ⇒ Object



186
187
188
189
190
191
192
193
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 186

def add(verb, clazz = MultiValueVerb)
  # if verb.respond_to?(:section_key)
  #   clazz=verb
  #   verb=clazz.section_key
  # end

  self.sections[Result.normalize_section_key(verb.to_s)] ||= clazz.new(verb)
end

#noObject



232
233
234
235
236
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 232

def no
  @no="no "
  @sections={}
  self
end

#no?Boolean

Returns:

  • (Boolean)


238
239
240
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 238

def no?
  @no
end

#render_verbs(verbs) ⇒ Object



222
223
224
225
226
227
228
229
230
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 222

def render_verbs(verbs)
  block=[]
  sections.keys.sort.each do |key|
    verb = sections[key]
    block << verb.serialize.map{|i| "  #{i}"}
  end

  block
end

#serializeObject



247
248
249
250
251
252
253
254
255
256
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 247

def serialize
  block=[]
  block << "#{@no}#{section.to_s}"
  unless (@no)
    block += render_verbs(self.sections)
    block << "exit"
  end

  block
end

#yesObject



242
243
244
245
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 242

def yes
  @no=nil
  self
end