Class: Bio::BaseSpace::QueryParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/basespace/model/query_parameters.rb

Overview

The QueryParameters class can be passed as an optional arguments for a specific sorting of list-responses (such as lists of Sample, AppResult, or Variant).

Constant Summary collapse

{
  'Statuses'    => [],
  'SortBy'      => ['Id', 'Name', 'DateCreated', 'Path', 'Position'],
  'Format'      => ['txt'],
  'Extensions'  => [],
  'Offset'      => [],
  'Limit'       => [],
  'SortDir'     => ['Asc', 'Desc'],
  'Name'        => [],
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pars = {}, required = ['SortBy', 'Offset', 'Limit', 'SortDir']) ⇒ QueryParameters

Create a new QueryParameters instance.

pars

Query parameters.

required

List of required query parameters.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/basespace/model/query_parameters.rb', line 41

def initialize(pars = {}, required = ['SortBy', 'Offset', 'Limit', 'SortDir'])
  @passed = {
    'SortBy'  => 'Id',
    'Offset'  => '0',    # [TODO] .to_i?
    'Limit'   => '100',  # [TODO] .to_i?
    'SortDir' => 'Asc',
  }
  pars.each do |k, v|
    @passed[k] = v
  end
  @required = required
end

Instance Attribute Details

#passedObject

Returns the value of attribute passed.



23
24
25
# File 'lib/basespace/model/query_parameters.rb', line 23

def passed
  @passed
end

#requiredObject

Returns the value of attribute required.



23
24
25
# File 'lib/basespace/model/query_parameters.rb', line 23

def required
  @required
end

Instance Method Details

#get_parameter_dictObject

Returns all query parameters.



65
66
67
# File 'lib/basespace/model/query_parameters.rb', line 65

def get_parameter_dict
  return @passed
end

#to_sObject

Returns a string representation of all query parameters contained in the object.



55
56
57
# File 'lib/basespace/model/query_parameters.rb', line 55

def to_s
  return @passed.to_s
end

#to_strObject

Returns a debugging string representation of the object.



60
61
62
# File 'lib/basespace/model/query_parameters.rb', line 60

def to_str
  return self.inspect
end

#validateObject

Check the validity of all query parameters.

Throws UndefinedParameterError if a required parameters is not present.



72
73
74
75
76
77
78
79
80
# File 'lib/basespace/model/query_parameters.rb', line 72

def validate
  @required.each do |p|
    raise UndefinedParameterError.new(p) unless @passed[p]
  end
  @passed.each do |p, v|
    raise UnknownParameterError.new(p) unless LEGAL[p]
    raise IllegalParameterError.new(p, LEGAL[p]) if (LEGAL[p].length > 0 and ! LEGAL[p].include?(@passed[p]))
  end
end