diff --git a/bindings/ruby/freej_extensions.rb b/bindings/ruby/freej_extensions.rb index 30d394b6..e24102ba 100644 --- a/bindings/ruby/freej_extensions.rb +++ b/bindings/ruby/freej_extensions.rb @@ -51,5 +51,18 @@ module Freej end self end + #apply the block to every element in the linked list and return an array + #with the resultant return values from the block + def collect(&block) + res = Array.new + index = 1 + item = self.pick(index) + while item != nil + res << block.call(item) + index = index + 1 + item = self.pick(index) + end + res + end end end diff --git a/scripts/ruby/list_filters.rb b/scripts/ruby/list_filters.rb new file mode 100755 index 00000000..1bd5d5ef --- /dev/null +++ b/scripts/ruby/list_filters.rb @@ -0,0 +1,18 @@ +#!/usr/bin/ruby +#for now update the load path to include the location of +#the freej module and freej_extensions [as we haven't installed it yet] +$: << '../../bindings/ruby/.libs' +$: << '../../bindings/ruby/' +##import the Freej module +require 'Freej' +#initializes Freej creating a Contex +cx = Freej::Context.new +#refresh the filter list +cx.plugger.refresh(cx) +#we collect because this creates a ruby array out of the filter linked list +#then we sort by name [case insensitive], then we print the name and description +#of each of the sorted filters +cx.filters.collect{|f| f}.sort {|x,y| x.name.downcase <=> y.name.downcase }.each do |f| + puts f.name + puts "\t#{f.description}" +end