Class: Construqt::Flavour::Ciscian::SingleValueVerb

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) ⇒ SingleValueVerb

Returns a new instance of SingleValueVerb.



132
133
134
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 132

def initialize(section)
  self.section=section
end

Instance Attribute Details

#sectionObject

Returns the value of attribute section.



131
132
133
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 131

def section
  @section
end

#valueObject

Returns the value of attribute value.



131
132
133
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 131

def value
  @value
end

Class Method Details

.compare(nu, old) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 141

def self.compare(nu, old)
  return [nu] unless old
  # return no changes (empty list) if old configuration of single value verb (default) is not explicitly reconfigured in new configuration:
  return [] unless nu
  return [nu] unless nu.serialize == old.serialize
  [nil]
end

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



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 170

def self.parse_line(line, lines, section, result)
  quotes = line.to_s.strip.end_with?("\"")
  regexp = quotes ? /^\s*((no|).*) \"([^"]+)\"$/ : /^\s*((no|).*) ([^\s"]+)$/
  if (line.to_s.strip =~ regexp)
    key=$1
    val=$3
    sec = section.add(key, Ciscian::SingleValueVerb).add(val)
    sec.quotes if quotes
  else
    section.add(line.to_s, Ciscian::SingleValueVerb)
  end
end

Instance Method Details

#add(value) ⇒ Object



149
150
151
152
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 149

def add(value)
  self.value=value
  self
end

#noObject



154
155
156
157
158
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 154

def no
  @no="no"
  self.value=nil
  self
end

#quotesObject



165
166
167
168
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 165

def quotes
  @quotes=true
  self
end

#serializeObject



136
137
138
139
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 136

def serialize
  val = @quotes ? "\"#{value}\"" : value
  [[@no, section , val].compact.join(" ")]
end

#yesObject



160
161
162
163
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 160

def yes
  @no=nil
  self
end