Module: Shellify::Utils
- Included in:
- Cli
- Defined in:
- lib/shellify/utils.rb
Instance Method Summary collapse
Instance Method Details
#duration_to_s(duration) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/shellify/utils.rb', line 8 def duration_to_s(duration) secs, _millis = duration.divmod(1000) mins, secs = secs.divmod(60) hours, mins = mins.divmod(60) hours = nil if hours.zero? [hours, mins, secs].compact.map { |s| s.to_s.rjust(2, '0') }.join(':') end |
#generate_oauth_url ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/shellify/utils.rb', line 20 def generate_oauth_url url_params = { response_type: 'code', client_id: @config.client_id, scope: Shellify::Config::SPOTIFY_AUTHORIZATION_SCOPES, redirect_uri: 'http://localhost:8888/callback', } "https://accounts.spotify.com/authorize?#{URI.encode_www_form(url_params)}" end |
#time_to_ms(time) ⇒ Object
16 17 18 |
# File 'lib/shellify/utils.rb', line 16 def time_to_ms(time) time.split(':').map(&:to_i).inject(0) { |a, b| a * 60 + b } * 1000 end |