Class: ReqUtils
- Inherits:
-
Object
- Object
- ReqUtils
- Defined in:
- lib/requtils.rb
Class Method Summary collapse
- .add_if_not_blank(to_fill, key, elem) ⇒ Object
- .assertIDRef(prefix, options) ⇒ Object
- .validateTrainingMetadata(to_validate) ⇒ Object
Class Method Details
.add_if_not_blank(to_fill, key, elem) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/requtils.rb', line 9 def self.add_if_not_blank(to_fill, key, elem) if (!elem.nil? && !elem.blank?) to_fill[key] = elem end return to_fill end |
.assertIDRef(prefix, options) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/requtils.rb', line 16 def self.assertIDRef(prefix, ) ref = prefix + '_id' id = prefix + '_reference' if (!.key?(ref) && !.key?(id)) raise RiminderArgumentException("'%s' or '%s' should exist in options"[ref, id]) end end |
.validateTrainingMetadata(to_validate) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/requtils.rb', line 24 def self.validateTrainingMetadata(to_validate) if (to_validate.kind_of?(NilClass) || to_validate.nil?) return to_validate end # True if have to be filled els otherwise mandatory_keys = {'filter_reference' => true, 'stage' => false, 'stage_timestamp' => false, 'rating' => false, 'rating_timestamp' => false} if (!to_validate.kind_of?(Array)) raise RiminderArgumentException.new('Training metadatas should be an array.') end mandatory_keys.each_pair{|key, shouldbefilled| to_validate.each {|to_validate_elem| if (!to_validate_elem.key?(key)) raise RiminderArgumentException.new('All training metadata should contain %s' [key]) end if (shouldbefilled && to_validate_elem[key].blank?) raise RiminderArgumentException.new('All training metadata should contain %s not nil or empty' [key]) end } } return to_validate end |