Module: Pexels::Client::SearchFilters

Included in:
Photos, Videos
Defined in:
lib/pexels/client/search_filters.rb

Constant Summary collapse

ORIENTATIONS =
%w(portrait landscape square).freeze
SIZES =
%w(small medium large).freeze
COLORS =
%w(red orange yellow green turquoise blue violet pink brown black gray white).freeze

Instance Method Summary collapse

Instance Method Details

#validate_color(color) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'lib/pexels/client/search_filters.rb', line 22

def validate_color(color)
  return true unless color
  return true if COLORS.include?(color.to_s)
  return true if color.to_s =~ /\A#?(?:[0-9a-f]{3}){1,2}\z/i

  raise ArgumentError, "`color` must be one of #{COLORS.join(', ')} or a valid hex code."
end

#validate_orientation(orientation) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
# File 'lib/pexels/client/search_filters.rb', line 8

def validate_orientation(orientation)
  return true unless orientation
  return true if ORIENTATIONS.include?(orientation.to_s)

  raise ArgumentError, "`orientation` must be one of #{ORIENTATIONS.join(', ')}."
end

#validate_size(size) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/pexels/client/search_filters.rb', line 15

def validate_size(size)
  return true unless size
  return true if SIZES.include?(size.to_s)

  raise ArgumentError, "`size` must be one of #{SIZES.join(', ')}."
end