Module: Id3Taginator::Extensions::ArgumentCheck

Included in:
Frames::Id3v2Frame
Defined in:
lib/id3taginator/extensions/argument_check.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • arg (String)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

  • bigger_than (Integer)

    string must have more than chars

  • smaller_than (Integer)

    string must have less than chars



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

Parameters:

  • arg (Object)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

Raises:

  • (ArgumentError)


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

Parameters:

  • arg (String)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

  • num_chars (Integer)

    number of chars to check against

Raises:

  • (ArgumentError)


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

Parameters:

  • arg (String)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

  • num_chars (Integer)

    number of chars to check against



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

Parameters:

  • arg (String)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

  • num_chars (Integer)

    number of chars to check against



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

Parameters:

  • arg (Object)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

Raises:

  • (ArgumentError)


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

Parameters:

  • arg (Object)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

Raises:

  • (ArgumentError)


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

Parameters:

  • arg (Object)

    the argument to check

  • arg_name (String)

    the argument name to use in the Error Message

Raises:

  • (ArgumentError)


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