Class/Module Index [+]

Quicksearch

Ruote::Exp::Condition

Public Class Methods

apply?(sif, sunless) click to toggle source
# File lib/ruote/exp/condition.rb, line 33
def self.apply? (sif, sunless)

  return (true?(sif)) if sif
  return ( ! true?(sunless)) if sunless

  true
end
true?(conditional) click to toggle source

TODO : rconditional

is it really necessary ? there is already ${r:xxx}
# File lib/ruote/exp/condition.rb, line 44
def self.true? (conditional)

  conditional = unescape(conditional)

  if m = SET_REGEX.match(conditional)
    eval_is(m)
  elsif m = COMPARISON_REGEX.match(conditional)
    compare(m)
  else
    to_b(conditional)
  end
end

Protected Class Methods

compare(m) click to toggle source
# File lib/ruote/exp/condition.rb, line 83
def self.compare (m)

  return (m[1].=~(Regexp.new(m[3])) != nil) if m[2] == '=~'

  a = narrow_to_f(m[1])
  b = narrow_to_f(m[3])

  if a.class != b.class
    a = m[1]
    b = m[3]
  end

  #a.send(m[2], b)
    # ruby 1.8.x doesn't like that one

  a = strip(a)
  b = strip(b)

  m[2] == '!=' ? ( ! a.send('==', b)) : a.send(m[2], b)
end
eval_is(match) click to toggle source
# File lib/ruote/exp/condition.rb, line 59
def self.eval_is (match)

  match = match[1..-2].select { |e| e != nil }

  negative = match.find { |m| m == ' not' }

  first = match.first.strip
  is_set = first != '' && first != 'is'

  negative ? (not is_set) : is_set
end
narrow_to_f(s) click to toggle source
# File lib/ruote/exp/condition.rb, line 104
def self.narrow_to_f (s)

  Float(s) rescue s
end
strip(s) click to toggle source
# File lib/ruote/exp/condition.rb, line 109
def self.strip (s)

  s.respond_to?(:strip) ? s.strip : s
end
to_b(o) click to toggle source
# File lib/ruote/exp/condition.rb, line 76
def self.to_b (o)

  o = o.strip if o.is_a?(String)

  not(o == nil || o == false || o == 'false' || o == '')
end
unescape(s) click to toggle source
# File lib/ruote/exp/condition.rb, line 71
def self.unescape (s)

  s ? s.to_s.gsub('&amp;', '&').gsub('&gt;', '>').gsub('&lt;', '<') : nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.