Module: Id3Taginator::Extensions::ArgumentCheck
- Included in:
- Frames::Id3v2Frame
- Defined in:
- lib/id3taginator/extensions/argument_check.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#argument_between_num(arg, arg_name, bigger_than, smaller_than) ⇒ Object
raises an ArgumentError if the given arguments number of chars is not in the given range.
-
#argument_boolean(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument is no Boolean.
-
#argument_exactly_chars(arg, arg_name, num_chars) ⇒ Object
raises an ArgumentError if the given argument has not the expected number of chars.
-
#argument_less_than_chars(arg, arg_name, num_chars) ⇒ Object
rubocop:disable Style/GuardClause raises an ArgumentError if the given argument has not the more than number of chars.
-
#argument_more_than_chars(arg, arg_name, num_chars) ⇒ Object
raises an ArgumentError if the given argument has not the more less number of chars.
-
#argument_not_empty(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument is no array or empty.
-
#argument_not_nil(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument is nil.
-
#argument_sym(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument no Symbol.
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 6 def self.included(base) base.extend(self) end |
Instance Method Details
#argument_between_num(arg, arg_name, bigger_than, smaller_than) ⇒ Object
raises an ArgumentError if the given arguments number of chars is not in the given range
80 81 82 83 84 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 80 def argument_between_num(arg, arg_name, bigger_than, smaller_than) if arg.nil? || arg > smaller_than || arg < bigger_than raise ArgumentError, "#{arg_name} must have be between #{bigger_than} and #{smaller_than}." end end |
#argument_boolean(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument is no Boolean
30 31 32 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 30 def argument_boolean(arg, arg_name) raise ArgumentError, "#{arg_name} must be boolean." unless !!arg == arg end |
#argument_exactly_chars(arg, arg_name, num_chars) ⇒ Object
raises an ArgumentError if the given argument has not the expected number of chars
47 48 49 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 47 def argument_exactly_chars(arg, arg_name, num_chars) raise ArgumentError, "#{arg_name} must have #{num_chars} characters." if arg.nil? || arg.length != num_chars end |
#argument_less_than_chars(arg, arg_name, num_chars) ⇒ Object
rubocop:disable Style/GuardClause raises an ArgumentError if the given argument has not the more than number of chars
57 58 59 60 61 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 57 def argument_less_than_chars(arg, arg_name, num_chars) if arg.nil? || arg.length > num_chars raise ArgumentError, "#{arg_name} must have less than #{num_chars} characters." end end |
#argument_more_than_chars(arg, arg_name, num_chars) ⇒ Object
raises an ArgumentError if the given argument has not the more less number of chars
68 69 70 71 72 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 68 def argument_more_than_chars(arg, arg_name, num_chars) if arg.nil? || arg.length < num_chars raise ArgumentError, "#{arg_name} must have more than #{num_chars} characters." end end |
#argument_not_empty(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument is no array or empty
38 39 40 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 38 def argument_not_empty(arg, arg_name) raise ArgumentError, "#{arg_name} can't be empty." if arg.nil? || (arg.is_a?(Array) && arg.empty?) end |
#argument_not_nil(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument is nil
14 15 16 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 14 def argument_not_nil(arg, arg_name) raise ArgumentError, "#{arg_name} can't be nil." if arg.nil? end |
#argument_sym(arg, arg_name) ⇒ Object
raises an ArgumentError if the given argument no Symbol
22 23 24 |
# File 'lib/id3taginator/extensions/argument_check.rb', line 22 def argument_sym(arg, arg_name) raise ArgumentError, "#{arg_name} must be sym." unless arg.is_a?(Symbol) end |