class RFlare::Spec
Public Class Methods
new(spec)
click to toggle source
# File lib/rflare.rb, line 56 def initialize spec @spec = spec.to_s raise "invalid spec '#{@spec}'" if @spec !~ /[+-]?([0-9]+|\*)(:([+-]?([0-9]+|\*))?)?/ end
Public Instance Methods
range(num, bounds)
click to toggle source
+ or - means relative to num, otherwise absolute
# File lib/rflare.rb, line 62 def range num, bounds bits = @spec.split ":", 2 s = bits.size == 1 ? @spec : bits[0] e = bits.size == 1 ? @spec : bits[1] range_start(num, bounds, s) .. range_end(num, bounds, e) end
Private Instance Methods
range_end(num, bounds, spec)
click to toggle source
# File lib/rflare.rb, line 86 def range_end num, bounds, spec if spec == '+*' or spec == '*' or spec == "" bounds.max elsif spec == '-*' num - 1 elsif spec[0] == '+' or spec[0] == '-' offset = spec[1, spec.length - 1].to_i spec[0] == '+' ? (num + offset) : (num - offset) else spec.to_i end end
range_start(num, bounds, spec)
click to toggle source
# File lib/rflare.rb, line 71 def range_start num, bounds, spec if spec == '+*' or spec == '*' num + 1 elsif spec == '-*' bounds.min elsif spec[0] == '+' or spec[0] == '-' offset = spec[1, spec.length - 1].to_i spec[0] == '+' ? (num + offset) : (num - offset) elsif spec == '' bounds.min else spec.to_i end end