diff options
author | Saku Ytti <saku@ytti.fi> | 2014-08-07 14:33:18 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-08-07 14:33:18 +0300 |
commit | 7aa9299971a2cacad29ab86e82cc780354d659e0 (patch) | |
tree | c932d85d28b2c6d654e3bfff75db00b6906c9af4 /lib/oxidized/string.rb | |
parent | 2a77796a7caf10601ae8edea5bf996f951694985 (diff) |
Keep config as Oxidized::Config instead of hash
The model will look like this:
cmd 'show ip cef' do |out|
out.type = 'poop'
out
end
cmd 'show process cpu' do |out|
out.type = 'poop'
out
end
cmd 'show memory statistics' do |out|
out.type = 'poop'
out
end
I think it's cleaner.
Diffstat (limited to 'lib/oxidized/string.rb')
-rw-r--r-- | lib/oxidized/string.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/oxidized/string.rb b/lib/oxidized/string.rb index 35dc5af..b17f896 100644 --- a/lib/oxidized/string.rb +++ b/lib/oxidized/string.rb @@ -1,13 +1,29 @@ module Oxidized # Used in models, contains convenience methods class String < String + attr_accessor :type, :cmd + # @return [Oxidized::String] copy of self with last line removed def cut_tail Oxidized::String.new each_line.to_a[0..-2].join end + # @return [Oxidized::String] copy of self with first line removed def cut_head Oxidized::String.new each_line.to_a[1..-1].join end + + # @return clean/filename version of cmd + def name + cmd.strip.gsub(/\s+/, '_') + end + + private + + def initialize arg + super + @type = 'cfg' + @cmd = 'n/a' + end end end |