class JarvisbotSongfinder::Provider

Abstract class for concrete providers to inherit from (Template Method Pattern)

Attributes

available_providers[RW]
errors[R]

Public Class Methods

new(config: JarvisbotSongfinder.configuration) click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 12
def initialize(config: JarvisbotSongfinder.configuration)
  @config = config
  @errors = []
end

Public Instance Methods

artist() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 25
def artist
  raise NotImplementedError
end
explicit?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 43
def explicit?
  raise NotImplementedError
end
length() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 17
def length
  raise NotImplementedError
end
provider() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 29
def provider
  raise NotImplementedError
end
title() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 21
def title
  raise NotImplementedError
end
url() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 39
def url
  raise NotImplementedError
end
valid?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 33
def valid?
  return false if @errors.any?

  available_in_region? && length_valid? && in_music_category?
end

Private Instance Methods

add_error(error) click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 49
def add_error(error)
  @errors << error unless @errors.include? error
end
available_in_region?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 53
def available_in_region?
  raise NotImplementedError
end
get_track() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 79
def get_track
  raise NotImplementedError
end
in_music_category?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 75
def in_music_category?
  raise NotImplementedError
end
length_valid?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 57
def length_valid?
  not_too_long? && not_too_short?
end
not_too_long?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 61
def not_too_long?
  unless length < @config.length_max
    add_error(JarvisbotSongfinder::ReplyMessage::Request.too_long)
  end
  length < @config.length_max
end
not_too_short?() click to toggle source
# File lib/jarvisbot_songfinder/providers/provider.rb, line 68
def not_too_short?
  unless length > @config.length_min
    add_error(JarvisbotSongfinder::ReplyMessage::Request.too_short)
  end
  length > @config.length_min
end