Advertisement
Guest User

Untitled

a guest
Dec 1st, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def entity_to_array(entity)
  2. return entity if entity.is_a?(Array)
  3. [entity]
  4. end
  5.  
  6. def get_array_entities(ent_array, using_entity)
  7. new_ent_array = []
  8. ent_array.each do |entity|
  9. #next if !entity.respond_to?(using_entity)
  10. next if !entity.respond_to?(using_entity)
  11.  
  12. entity_value = entity.send(using_entity)
  13. new_ent_array.push entity_value
  14. end
  15. new_ent_array.flatten
  16. end
  17.  
  18. def get_object_entity(ent_obj, using_entity)
  19. if ent_obj.respond_to?(using_entity) then
  20. entity_value = ent_obj.send(using_entity)
  21. else
  22. #can't respond to anything so return an empty array
  23. return []
  24. end
  25. entity_to_array(entity_value)
  26. end
  27.  
  28.  
  29. #this code works, but i feel its messy, but don't know how ;)
  30.  
  31. forms = get_object_entity(self, :forms)
  32. fields = get_array_entities(forms, :fields)
  33. names = get_array_entities(fields, :name)
  34.  
  35. #a symbol is getting sent to this function which describes the search parameters
  36. #so it could change and not static..
  37. #ex.. :exists_forms_fields_name, 'joe blow'
  38.  
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement