Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
style: rubcop warnings fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Apr 29, 2020
1 parent d40f9b2 commit ad8fb22
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activesupport', '>=6.0.2.2'
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rake/testtask'

Rake::TestTask.new do |test|
Expand Down
1 change: 1 addition & 0 deletions bin/mp3lyrics
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'mp3lyrics'
7 changes: 4 additions & 3 deletions lib/mp3lyrics.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'mp3info'
require 'require_all'

Expand Down Expand Up @@ -75,6 +77,7 @@ def usage_message(override_options, use_options)
files.each do |file|
filename = File.extname(file)
next unless filename == '.mp3'

Mp3Info.open(file) do |mp3|
artist = mp3.tag.artist || mp3.tag1.artist || mp3.tag2.artist
title = mp3.tag.title || mp3.tag1.title || mp3.tag2.title
Expand All @@ -86,9 +89,7 @@ def usage_message(override_options, use_options)
# Either no tag is set, the mp3 file has no USLT tag or we override anyway
if !mp3.hastag2? || (mp3.hastag2? && !mp3.tag2.key?('USLT')) || override
lyrics = nil
if wiki_to_use.nil? || wiki_to_use == 'lyricwiki'
lyrics = LyricWiki.new.get_lyrics(artist, title)
end
lyrics = LyricWiki.new.get_lyrics(artist, title) if wiki_to_use.nil? || wiki_to_use == 'lyricwiki'
if wiki_to_use.nil? || wiki_to_use == 'genius'
lyrics = Genius.new.get_lyrics(artist, title) if lyrics.nil?
end
Expand Down
2 changes: 2 additions & 0 deletions lib/wiki/azlyrics.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './wiki'

# Fetches the lyrics from AZLyrics.com
Expand Down
3 changes: 3 additions & 0 deletions lib/wiki/genius.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './wiki'

# Fetches the lyrics from Genius (formerly known as Rap Genius)
Expand All @@ -12,6 +14,7 @@ def get_lyrics(artist, song, limit = 10)

res = fetch("https://genius.com/#{artist.downcase}-#{song.downcase}-lyrics", limit)
return nil unless res.is_a? Net::HTTPSuccess

lyrics = Nokogiri::HTML(res.body).xpath('//div[@class="lyrics"]//p[1]')
lyrics.inner_html.gsub('<br>', "\r").gsub(%r{</?[^>]+>}, '').delete("\n")
end
Expand Down
2 changes: 2 additions & 0 deletions lib/wiki/lyricwiki.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './wiki'

# Fetches the lyrics from LyricWiki
Expand Down
2 changes: 2 additions & 0 deletions lib/wiki/metrolyrics.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './wiki'

# Fetches the lyrics from MetroLyrics
Expand Down
5 changes: 4 additions & 1 deletion lib/wiki/wiki.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/inflector'
require 'net/http'
require 'nokogiri'
Expand All @@ -6,6 +8,7 @@
class Wiki
def fetch(uri_str, limit = 10)
raise ArgumentError, 'The wiki site is redirecting too much, aborting...' if limit.zero?

uri = prepare_url(uri_str)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
req = Net::HTTP::Get.new(uri.path)
Expand All @@ -16,7 +19,7 @@ def fetch(uri_str, limit = 10)
end
end
case response
when Net::HTTPRedirection then
when Net::HTTPRedirection
fetch(response['location'], limit - 1)
else
response
Expand Down
2 changes: 2 additions & 0 deletions mp3lyrics.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Gem::Specification.new do |s|
s.name = 'mp3lyrics'
s.version = '0.1.0'
Expand Down
2 changes: 2 additions & 0 deletions test/azlyrics_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './spec_helper'
require_relative '../lib/wiki/azlyrics'

Expand Down
1 change: 1 addition & 0 deletions test/codeclimate-transform.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /bin/ruby
# frozen_string_literal: true

# Temporary hack to get CodeClimate to work with SimpleCov 0.18 JSON format until issue is fixed
# upstream: https://github.com/codeclimate/test-reporter/issues/413
Expand Down
2 changes: 2 additions & 0 deletions test/genius_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './spec_helper'
require_relative '../lib/wiki/genius'

Expand Down
2 changes: 2 additions & 0 deletions test/lyricwiki_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './spec_helper'
require_relative '../lib/wiki/lyricwiki'

Expand Down
2 changes: 2 additions & 0 deletions test/metrolyrics_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative './spec_helper'
require_relative '../lib/wiki/metrolyrics'

Expand Down
2 changes: 2 additions & 0 deletions test/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'simplecov'
require 'minitest/autorun'

Expand Down

0 comments on commit ad8fb22

Please sign in to comment.