Sha256: aedf8e12bcb3e4181a2dec9cb036b436ccbc68d3994c09cdffafade08ce02e21
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
module Hieracles module Puppetdb class Query def initialize(elements) @elements = parse(elements) end def parse(elements) items = [] index = 0 if elements.length > 1 elements.each do |e| puts items.inspect if e == 'or' index++ continue end if /(.*)(>|<|=|!=|~)(.*)/.match e items[index] ||= [] items[index] << [$2, $1, $3] end end else if /(.*)(>|<|=|!=|~)(.*)/.match elements[0] items = [$2, $1, $3] end end items end def output back = [] if @elements.length > 1 back << 'or' @elements.each do |e| back << build_and(e) end else @elements.each do |e| back << build_and(e) end end back end def build_and(arrays) if arrays.length > 1 ['and', arrays] else arrays end end def defined? @elements.count > 0 end def match(item) @elements.each do |e| matched = false e.each do |a| case a[0] when '=' when '!=' when '<' when '>' when '!' else end end return true if matched end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hieracles-0.2.2 | lib/hieracles/puppetdb/query.rb |
hieracles-0.2.1 | lib/hieracles/puppetdb/query.rb |