Module: Quintype::API::BaseFunctions::ClassFunctions
- Defined in:
- lib/quintype/api/base_functions.rb
Instance Method Summary collapse
- #coerce_array(key, clazz) ⇒ Object
- #coerce_key(key, clazz) ⇒ Object
- #from_hash(hash, *args) ⇒ Object
- #members_as_string ⇒ Object
Instance Method Details
#coerce_array(key, clazz) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/quintype/api/base_functions.rb', line 12 def coerce_array(key, clazz) class_eval <<-EOF def #{key.to_s} super.map { |i| #{clazz.name}.from_hash(i)} end EOF end |
#coerce_key(key, clazz) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/quintype/api/base_functions.rb', line 20 def coerce_key(key, clazz) class_eval <<-EOF def #{key.to_s} #{clazz.name}.from_hash(i) end EOF end |
#from_hash(hash, *args) ⇒ Object
8 9 10 |
# File 'lib/quintype/api/base_functions.rb', line 8 def from_hash(hash, *args) new *(args + hash.values_at(*members_as_string)) end |
#members_as_string ⇒ Object
4 5 6 |
# File 'lib/quintype/api/base_functions.rb', line 4 def members_as_string @members_as_string ||= members.map(&:to_s) end |