Class: Construqt::Flavour::Ciscian::NestedSection
- Inherits:
-
Object
- Object
- Construqt::Flavour::Ciscian::NestedSection
- Defined in:
- lib/construqt/flavour/ciscian/ciscian.rb
Instance Attribute Summary collapse
-
#section ⇒ Object
Returns the value of attribute section.
-
#sections ⇒ Object
Returns the value of attribute sections.
Class Method Summary collapse
Instance Method Summary collapse
- #add(verb, clazz = SingleValueVerb) ⇒ Object
-
#initialize(section) ⇒ NestedSection
constructor
A new instance of NestedSection.
- #no ⇒ Object
- #no? ⇒ Boolean
- #render_verbs(verbs) ⇒ Object
- #serialize ⇒ Object
- #virtual ⇒ Object
- #yes ⇒ Object
Constructor Details
#initialize(section) ⇒ NestedSection
Returns a new instance of NestedSection.
186 187 188 189 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 186 def initialize(section) self.sections={} self.section=section end |
Instance Attribute Details
#section ⇒ Object
Returns the value of attribute section.
185 186 187 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 185 def section @section end |
#sections ⇒ Object
Returns the value of attribute sections.
185 186 187 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 185 def sections @sections end |
Class Method Details
.compare(nu, old) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 271 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).uniq.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
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 201 def self.parse_line(line, lines, section, result) 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, NestedSection) do |_section| _section.virtual if result.dialect.is_virtual?(resultline.to_s) 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::(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), NestedSection) do |_section| _section.sections.merge!(section_to_split.sections) end end end end return true end end |
Instance Method Details
#add(verb, clazz = SingleValueVerb) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 191 def add(verb, clazz = SingleValueVerb) section_key=Result.normalize_section_key(verb.to_s) self.sections[section_key] ||= clazz.new(section_key) if Result.starts_with_no(verb.to_s) @sections[section_key].no end @sections[section_key] end |
#no ⇒ Object
238 239 240 241 242 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 238 def no @no="no " @sections={} self end |
#no? ⇒ Boolean
244 245 246 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 244 def no? @no end |
#render_verbs(verbs) ⇒ Object
228 229 230 231 232 233 234 235 236 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 228 def render_verbs(verbs) block=[] sections.keys.sort.each do |key| verb = sections[key] block << verb.serialize.map{|i| " #{i}"} end block end |
#serialize ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 258 def serialize block=[] if (!self.sections.empty? || (self.sections.empty? && @virtual) || (@no && @virtual)) block << "#{@no}#{section.to_s}" unless (@no) block += render_verbs(self.sections) block << "exit" end end block end |
#virtual ⇒ Object
253 254 255 256 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 253 def virtual @virtual=true self end |
#yes ⇒ Object
248 249 250 251 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 248 def yes @no=nil self end |