lib/biomart/dataset.rb in biomart-0.2.0 vs lib/biomart/dataset.rb in biomart-0.2.1

- old
+ new

@@ -4,10 +4,23 @@ class Dataset include Biomart attr_reader :name, :display_name, :visible + # Creates a new Biomart::Dataset object. + # + # @param [String] url The URL location of the biomart server. + # @param [Hash] args An arguments hash giving details of the dataset. + # + # arguments hash: + # + # { + # :name => String, # + # "name" => String, # + # :display_name => {} # + # + # } def initialize( url, args ) @url = url or raise ArgumentError, "must pass :url" unless @url =~ /martservice/ @url = @url + "/martservice" end @@ -233,18 +246,33 @@ def dataset_xml( xml, dataset, args ) xml.Dataset( :name => dataset.name, :interface => "default" ) { if args[:filters] args[:filters].each do |name,value| - if value.is_a? Array - value = value.join(",") + raise Biomart::ArgumentError, "The filter '#{name}' does not exist" if dataset.filters[name].nil? + + if dataset.filters[name].type == 'boolean' + value = value.downcase if value.is_a? String + if [true,'included','only'].include?(value) + xml.Filter( :name => name, :excluded => '0' ) + elsif [false,'excluded'].include?(value) + xml.Filter( :name => name, :excluded => '1' ) + else + raise Biomart::ArgumentError, "The boolean filter '#{name}' can only accept 'true/included/only' or 'false/excluded' arguments." + end + else + value = value.join(",") if value.is_a? Array + xml.Filter( :name => name, :value => value ) end - xml.Filter( :name => name, :value => value ) end else dataset.filters.each do |name,filter| if filter.default? - xml.Filter( :name => name, :value => filter.default_value ) + if filter.type == 'boolean' + xml.Filter( :name => name, :excluded => filter.default_value ) + else + xml.Filter( :name => name, :value => filter.default_value ) + end end end end unless args[:count] \ No newline at end of file