Module: Mspire::Mascot::Dat::Castable

Included in:
Header, Parameters, Peptide, Query
Defined in:
lib/mspire/mascot/dat/cast.rb

Instance Method Summary collapse

Instance Method Details

#cast!(cast_hash = nil) ⇒ Object

expects a hash with the parameter and the way to cast it as a symbol (e.g., :to_f or a lambda). If no hash given, will attempt to retrieve a class constant ‘CAST’ which defines the casts.



16
17
18
19
20
21
22
23
24
25
# File 'lib/mspire/mascot/dat/cast.rb', line 16

def cast!(cast_hash=nil)
  hash = cast_hash || self.class.const_get('CAST')
  self.each_pair do |k,v|
    if cast=hash[k]
      apply = cast.is_a?(Symbol) ? cast.to_proc : cast
      self[k] = apply[v] if apply
    end
  end
  self
end