Sha256: 99e685f2c5ee1076886be7734a10d361d376bba3c88425c88a858bea918225cb
Contents?: true
Size: 956 Bytes
Versions: 4
Compression:
Stored size: 956 Bytes
Contents
module NagiosCheck class Range def initialize(string_range) if string_range.nil? || string_range.empty? raise RuntimeError, "Pattern should not be nil" end @string_range = string_range tokens = string_range.scan(/^(@)?(([-.0-9]+|~)?:)?([-.0-9]+)?$/).first unless tokens raise RuntimeError, "Pattern should be of form [@][~][min]:max" end @inverse = true if tokens.include? "@" case tokens[2] when nil, "" then @min = 0 when '~' then @min = nil else @min = tokens[2].to_f end @max = tokens[3].nil? || tokens[3] == "" ? nil : tokens[3].to_f end def include?(value) result = (@min.nil? || value >= @min) && (@max.nil? || value <= @max) @inverse ? not(result) : result end def ===(value) include?(value) end def to_s "Range[#{@reversed ? "~" : ""}#{@inclusive ? "@" : ""}#{@min}:#{@max}]" end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
nagios_check-0.4.1 | lib/nagios_check/range.rb |
nagios_check-0.4.0 | lib/nagios_check/range.rb |
nagios_check-0.3.1 | lib/nagios_check/range.rb |
nagios_check-0.3.0 | lib/nagios_check/range.rb |