diff options
Diffstat (limited to 'lib/custodian/parser.rb')
-rw-r--r-- | lib/custodian/parser.rb | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb index 2d08519..ae771db 100644 --- a/lib/custodian/parser.rb +++ b/lib/custodian/parser.rb @@ -123,13 +123,13 @@ module Custodian # # Get the name of the macro. # - name = $1.dup if line =~ /^([0-9A-Z_]+)\s+/ + name = $1.dup if line =~ /^([0-9A-Z_]+)\s+/ # # Get the value # - if line =~ /fetched\s+from\s+(.*)[\r\n\.]*$/ + if line =~ /fetched\s+from\s+(.*)[\r\n\.]*$/ # # HTTP-fetch @@ -138,10 +138,10 @@ module Custodian text = get_url_contents(uri) text.split(/[\r\n]/).each do |line| - val.push(line) if line.length > 0 + val.push(line) if line.length > 0 end - elsif line =~ /\s(is|are)\s+(.*)\.*$/ + elsif line =~ /\s(is|are)\s+(.*)\.*$/ # # Literal list of hosts @@ -151,7 +151,7 @@ module Custodian # # If there is " and " then tokenize # - if hosts =~ /\s+and\s+/ + if hosts =~ /\s+and\s+/ tmp = hosts.split(/\s+and\s+/) tmp.each do |entry| val.push(entry) @@ -164,7 +164,7 @@ module Custodian end end - if is_macro?(name) + if is_macro?(name) raise ArgumentError, "The macro #{name} is already defined" end @@ -213,13 +213,13 @@ module Custodian r = [] - if input =~ /^(\S+)\s+(.*)$/ + if input =~ /^(\S+)\s+(.*)$/ macro = $1.dup rest = $2.dup end - if is_macro?(macro) + if is_macro?(macro) get_macro_targets(macro).each do |host| r.push("#{host} #{rest}") end @@ -238,19 +238,19 @@ module Custodian raise ArgumentError, "Line is not a string: #{line}" unless line.kind_of? String - line.chomp! if !line.nil? + line.chomp! if !line.nil? - line.strip! if !line.nil? + line.strip! if !line.nil? # # A blank line, or a comment may be skipped. # - return nil if (line.nil?) || (line =~ /^#/) || (line.length < 1) + return nil if (line.nil?) || (line =~ /^#/) || (line.length < 1) # # Look for a time period. # - if line =~ /between\s+([0-9]+)-([0-9]+)/i + if line =~ /between\s+([0-9]+)-([0-9]+)/i # # The starting/ending hours. @@ -271,23 +271,23 @@ module Custodian # # Should we exclude the test? # - if line =~ /except\s+between/i - return nil if inside + if line =~ /except\s+between/i + return nil if inside else - return nil if !inside + return nil if !inside end end # # Look for macro definitions, inline # - if line =~ /^([0-9A-Z]_+)\s+are\s+fetched\s+from\s+([^\s]+)\.?/ + if line =~ /^([0-9A-Z]_+)\s+are\s+fetched\s+from\s+([^\s]+)\.?/ define_macro(line) - elsif line =~ /^([0-9A-Z_]+)\s+(is|are)\s+/ + elsif line =~ /^([0-9A-Z_]+)\s+(is|are)\s+/ define_macro(line) - elsif line =~ /^(\S+)\s+must\s+ping(.*)/ + elsif line =~ /^(\S+)\s+must\s+ping(.*)/ # # Ping is a special case because the configuration file entry # would read: @@ -309,7 +309,7 @@ module Custodian new_line = "#{pre} must run ping #{post}" return(parse_line(new_line)) - elsif line =~ /^\S+\s+must(\s+not)?\s+run\s+([^\s]+)(\s+|\.|$)/i + elsif line =~ /^\S+\s+must(\s+not)?\s+run\s+([^\s]+)(\s+|\.|$)/i # # Expand the macro if we should @@ -367,8 +367,8 @@ module Custodian # # If we're given a string then split it on newline # - if text.kind_of?(String) - a = text.split(/[\r\n]/) + if text.kind_of?(String) + a = text.split(/[\r\n]/) text = a end @@ -410,7 +410,7 @@ module Custodian # def parse_file(filename) - raise ArgumentError, 'Missing configuration file!' if filename.nil? + raise ArgumentError, 'Missing configuration file!' if filename.nil? raise ArgumentError, "File not found: #{@file}" unless File.exist?(filename) # |