Module: Acoustid::API::Request::ParamValidations
- Included in:
- Base
- Defined in:
- lib/acoustid/api/request/param_validations.rb
Constant Summary collapse
- VALID_META_VALUES =
%W[recordings recordingids releases releaseids releasegroups releasegroupids tracks compress usermeta sources]
Instance Method Summary collapse
- #serialize_integer(value) ⇒ Object
- #serialize_meta(value) ⇒ Object
- #serialize_string(value) ⇒ Object
- #validate_duration(value) ⇒ Object
- #validate_format(value) ⇒ Object
- #validate_meta(value) ⇒ Object
Instance Method Details
#serialize_integer(value) ⇒ Object
13 14 15 |
# File 'lib/acoustid/api/request/param_validations.rb', line 13 def serialize_integer(value) value.nil? ? nil : value.to_i end |
#serialize_meta(value) ⇒ Object
17 18 19 |
# File 'lib/acoustid/api/request/param_validations.rb', line 17 def (value) value.nil? ? nil : value.to_a.collect { |value| value.to_s.strip } end |
#serialize_string(value) ⇒ Object
9 10 11 |
# File 'lib/acoustid/api/request/param_validations.rb', line 9 def serialize_string(value) value.nil? ? nil : value.to_s.strip end |
#validate_duration(value) ⇒ Object
25 26 27 |
# File 'lib/acoustid/api/request/param_validations.rb', line 25 def validate_duration(value) raise TypeError, 'duration must respond to :to_i' unless value.respond_to?(:to_i) end |
#validate_format(value) ⇒ Object
21 22 23 |
# File 'lib/acoustid/api/request/param_validations.rb', line 21 def validate_format(value) raise ArgumentError, '' unless %W[json jsonp xml].include?(value.to_s.strip) end |
#validate_meta(value) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/acoustid/api/request/param_validations.rb', line 29 def (value) raise TypeError, 'meta must respond to :to_a or be nil' unless value.nil? || value.respond_to?(:to_a) raise TypeError, "meta must only include #{ VALID_META_VALUES.join(', ') }" unless value.nil? || (value).all? { || VALID_META_VALUES.include?() } # TODO end |