class Bio::BaseSpace::Model
Base class for all BaseSpace
Ruby SDK model classes. Implements a basic key/value store and provides convenience methods for accessing the key/value store using ‘method_missing` magic.
Keys in this model are referred to as “attribute names”, whereas values are called “attributes”.
Attributes
Public Class Methods
Create a new (empty) model.
# File lib/basespace/model.rb, line 27 def initialize @swagger_types = {} @attributes = {} end
Public Instance Methods
Returns the value, if any, of the given attribute name.
key
-
Attribute name whose value should be returned.
# File lib/basespace/model.rb, line 67 def get_attr(key) return @attributes[key] end
If a method was called on the object for which no implementations is provided, then execute this method and try to return the attribute value whose attribute key matches the method call’s name.
method
-
Method call for which no implementation could be found.
args
-
Arguments that were provided to the method call.
block
-
If not nil, code block that follows the method call.
# File lib/basespace/model.rb, line 39 def method_missing(method, *args, &block) attr_name = method.to_s.downcase.gsub('_', '') attr_value = false self.attributes.each do |key, value| if key.downcase == attr_name attr_value = value # can be an object or nil end end if attr_value == false super else return attr_value end end
Sets the value of a named attribute. Overrides the value of a previous assignment.
key
-
Attribute name whose value should be set.
value
-
Value that should be assigned.
# File lib/basespace/model.rb, line 59 def set_attr(key, value) @attributes[key] = value return @attributes end
Returns a string representation of the model.
# File lib/basespace/model.rb, line 72 def to_s return self.inspect end