Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Refactor to model more of the properties of the Attributes and Filter…
Browse files Browse the repository at this point in the history
…s. [Closes #9]
  • Loading branch information
dazoakley committed Mar 20, 2010
1 parent 547554f commit de9b477
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
15 changes: 14 additions & 1 deletion lib/biomart/attribute.rb
Expand Up @@ -2,13 +2,26 @@ module Biomart
# Class representation for a biomart attribute.
# Will belong to a Biomart::Dataset.
class Attribute
attr_reader :name, :display_name, :default
attr_reader :name, :display_name

def initialize(args)
@name = args["internalName"]
@display_name = args["displayName"]
@default = args["default"] ? true : false
@hidden = args["hideDisplay"] ? true : false
end

# Convenience method to see if this attribute is hidden from
# the standard MartView interface. Returns true/false.
def hidden?
@hidden
end

# Convenience method to see if this attribute would be
# enabled by default in the standard MartView interface.
# Returns true/false.
def default?
@default
end
end
end
6 changes: 6 additions & 0 deletions lib/biomart/database.rb
Expand Up @@ -36,6 +36,12 @@ def datasets
return @datasets
end

# Returns true / false if this database is visbile in the
# default MartView interface.
def visible?
@visible
end

private

# Utility method to do the webservice call to the biomart server
Expand Down
6 changes: 3 additions & 3 deletions lib/biomart/dataset.rb
Expand Up @@ -129,7 +129,7 @@ def generate_xml( args={} )
end
else
self.filters.each do |name,filter|
if filter.default
if filter.default?
xml.Filter( :name => name, :value => filter.default_value )
end
end
Expand All @@ -142,7 +142,7 @@ def generate_xml( args={} )
end
else
self.attributes.each do |name,attribute|
if attribute.default
if attribute.default?
xml.Attribute( :name => name )
end
end
Expand Down Expand Up @@ -202,7 +202,7 @@ def process_tsv( args, tsv )
end
else
self.attributes.each do |name,attribute|
if attribute.default
if attribute.default?
headers.push(name)
end
end
Expand Down
32 changes: 27 additions & 5 deletions lib/biomart/filter.rb
Expand Up @@ -2,14 +2,36 @@ module Biomart
# Class representation for a biomart filter.
# Will belong to a Biomart::Dataset.
class Filter
attr_reader :name, :display_name, :default, :default_value
attr_reader :name, :display_name, :default_value, :qualifier, :type

def initialize(args)
@name = args["internalName"]
@display_name = args["displayName"]
@default = args["defaultOn"] ? true : false
@default_value = args["defaultValue"]
@name = args["internalName"]
@display_name = args["displayName"]
@default = args["defaultOn"] ? true : false
@default_value = args["defaultValue"]
@hidden = args["hideDisplay"] ? true : false
@qualifier = args["qualifier"]
@type = args["type"]
@multiple_values = args["multipleValues"] ? true : false
end

# Convenience method to see if this filter is hidden from
# the standard MartView interface. Returns true/false.
def hidden?
@hidden
end

# Convenience method to see if this filter would be
# enabled by default in the standard MartView interface.
# Returns true/false.
def default?
@default
end

# Convenience method to see if this filter allows multiple
# values to be passed to it.
def multiple_values?
@multiple_values
end
end
end
4 changes: 1 addition & 3 deletions lib/biomart/server.rb
Expand Up @@ -73,9 +73,7 @@ def fetch_databases
url = @url + '?type=registry'
document = REXML::Document.new( request( :url => url ) )
REXML::XPath.each( document, "//MartURLLocation" ) do |d|
if d.attributes["visible"] === "1"
@databases[ d.attributes["name"] ] = Database.new( @url, d.attributes )
end
@databases[ d.attributes["name"] ] = Database.new( @url, d.attributes )
end
end

Expand Down

0 comments on commit de9b477

Please sign in to comment.