mirror of
https://github.com/dyne/FreeJ.git
synced 2026-06-16 12:59:33 +02:00
Ruby binding: linklist collect method
added a collect method for freej's linked lists in the ruby binding. Created an example script which uses this to print out a list of the installed filters, sorted by name.
This commit is contained in:
@@ -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
|
||||
|
||||
Executable
+18
@@ -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
|
||||
Reference in New Issue
Block a user