Skip to content

Commit

Permalink
🚨 run rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
YutaGoto committed Apr 12, 2023
1 parent 0cd337f commit 8e55911
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 99 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

Expand Down
9 changes: 5 additions & 4 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

target :lib do
signature "sig"
signature 'sig'

check "lib"
repo_path ".gem_rbs_collection"
check 'lib'
repo_path '.gem_rbs_collection'
end

13 changes: 3 additions & 10 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "ika3"
require 'bundler/setup'
require 'ika3'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
33 changes: 16 additions & 17 deletions ika3.gemspec
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# frozen_string_literal: true

require_relative "lib/ika3/version"
require_relative 'lib/ika3/version'

Gem::Specification.new do |spec|
spec.name = "ika3"
spec.name = 'ika3'
spec.version = Ika3::VERSION
spec.authors = ["YutaGoto"]
spec.email = ["[email protected]"]
spec.authors = ['YutaGoto']
spec.email = ['[email protected]']

spec.summary = "Splatoon3 weapons information library."
spec.description = "Splatoon3 weapons information library. This gem provide weapon name, sub, and special. not official"
spec.homepage = "https://github.com/YutaGoto/ika3"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.7.0"
spec.summary = 'Splatoon3 weapons information library.'
spec.description = 'Splatoon3 weapons information library. This gem provide weapon name, sub, and special. not official'
spec.homepage = 'https://github.com/YutaGoto/ika3'
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.7.0'

# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/YutaGoto/ika3"
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/YutaGoto/ika3'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -26,13 +24,14 @@ Gem::Specification.new do |spec|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "faraday", ">= 2.7.0"
spec.add_dependency "activesupport", ">= 5.0.0"
spec.add_dependency 'activesupport', '>= 5.0.0'
spec.add_dependency 'faraday', '>= 2.7.0'

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
spec.metadata['rubygems_mfa_required'] = 'true'
end
18 changes: 9 additions & 9 deletions lib/ika3.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require "yaml"
require 'yaml'

require "active_support/core_ext/hash/keys"
require "active_support/core_ext/string/inflections"
require "faraday"
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/string/inflections'
require 'faraday'

require "ika3/version"
require "ika3/concerns/utils"
require "ika3/response"
require "ika3/weapons"
require "ika3/schedule"
require 'ika3/version'
require 'ika3/concerns/utils'
require 'ika3/response'
require 'ika3/weapons'
require 'ika3/schedule'

module Ika3
class Error < StandardError; end
Expand Down
3 changes: 2 additions & 1 deletion lib/ika3/concerns/utils.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

module Ika3
module Concerns
module Utils

module_function

def load_yaml_file(file)
Expand Down
4 changes: 3 additions & 1 deletion lib/ika3/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Ika3
class Response
def initialize(faraday_response)
Expand All @@ -12,7 +14,7 @@ def body

def headers
@headers ||= @raw_headers.inject({}) do |result, (key, value)|
result.merge(key.split("-").map(&:capitalize).join("-") => value)
result.merge(key.split('-').map(&:capitalize).join('-') => value)
end
end

Expand Down
28 changes: 20 additions & 8 deletions lib/ika3/schedule.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# frozen_string_literal: true

class Hash
def respond_to_missing?(sym)
key? name ? true : super
end

def method_missing(name)
return self[name] if key? name

Expand All @@ -13,22 +19,28 @@ def initialize(contact)
@contact = contact
end

modes = ["regular", "bankara_challenge", "bankara_open", "x"]
schedules = ["now", "next"]
modes = %w[regular bankara_challenge bankara_open x]
schedules = %w[now next]

schedules.each do |schedule|
modes.each do |mode|
define_method("#{mode}_#{schedule}".to_sym) do
return instance_variable_get("@#{mode}_#{schedule}_obj") if instance_variable_defined?("@#{mode}_#{schedule}_obj")
if instance_variable_defined?("@#{mode}_#{schedule}_obj")
return instance_variable_get("@#{mode}_#{schedule}_obj")
end

instance_variable_set("@#{mode}_#{schedule}_obj", send_request(:get, "/api/#{mode.dasherize}/#{schedule}").body.results[0])
instance_variable_set("@#{mode}_#{schedule}_obj",
send_request(:get, "/api/#{mode.dasherize}/#{schedule}").body.results[0])
end
end

define_method("salmon_run_#{schedule}".to_sym) do
return instance_variable_get("@salmon_run_#{schedule}_obj") if instance_variable_defined?("@salmon_run_#{schedule}_obj")
if instance_variable_defined?("@salmon_run_#{schedule}_obj")
return instance_variable_get("@salmon_run_#{schedule}_obj")
end

instance_variable_set("@salmon_run_#{schedule}_obj", send_request(:get, "/api/coop-grouping/#{schedule}").body.results[0])
instance_variable_set("@salmon_run_#{schedule}_obj",
send_request(:get, "/api/coop-grouping/#{schedule}").body.results[0])
end
end

Expand All @@ -40,11 +52,11 @@ def send_request(method, path)
end

def api_url
"https://spla3.yuu26.com/"
'https://spla3.yuu26.com/'
end

def splat3_connection
@splat3_connection ||= Faraday::new(faraday_options) do |c|
@splat3_connection ||= Faraday.new(faraday_options) do |c|
c.request :json
c.response :json
c.adapter Faraday.default_adapter
Expand Down
2 changes: 1 addition & 1 deletion lib/ika3/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Ika3
VERSION = "0.4.0"
VERSION = '0.4.0'
end
20 changes: 9 additions & 11 deletions lib/ika3/weapons.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module Ika3
class Weapon
ATTRIBUTES = [
:name, :sub, :special
ATTRIBUTES = %i[
name sub special
].freeze

ATTRIBUTES.each do |attribute|
Expand Down Expand Up @@ -35,13 +37,13 @@ def find_by_name(weapon_name)
def filter_by_sub(sub_name)
raise "unknown sub weapon: #{sub_name}" unless sub_weapons.values.include?(sub_name)

config.values.filter{|weapon| weapon[:sub] == sub_name}
config.values.filter { |weapon| weapon[:sub] == sub_name }
end

def reload_config!
@cache = {}
@config = nil
@config_sub_weapons = nil
@sub_weapons = nil
config
config_sub_weapons
end
Expand Down Expand Up @@ -73,17 +75,13 @@ def sub_weapons
end

def config
unless @config
@config = load_yaml_file("#{File.dirname(__FILE__)}/../../config/weapons.yml").deep_symbolize_keys
end
@config ||= load_yaml_file("#{File.dirname(__FILE__)}/../../config/weapons.yml").deep_symbolize_keys
@config
end

def config_sub_weapons
unless @config_sub_weapons
@config_sub_weapons = load_yaml_file("#{File.dirname(__FILE__)}/../../config/sub_weapons.yml").deep_symbolize_keys
end
@config_sub_weapons
@sub_weapons ||= load_yaml_file("#{File.dirname(__FILE__)}/../../config/sub_weapons.yml").deep_symbolize_keys
@sub_weapons
end

def valid?(weapon_key)
Expand Down
24 changes: 13 additions & 11 deletions spec/ika3/schedule_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# frozen_string_literal: true

RSpec.describe Ika3::Schedule do
let(:schedule) {described_class.new(contact_info)}
let(:contact_info) {"@YutaGoto_rspec"}
let(:schedule) { described_class.new(contact_info) }
let(:contact_info) { '@YutaGoto_rspec' }

describe "#regular_now" do
it "get current regular match" do
expect(schedule.regular_now).to include("start_time")
describe '#regular_now' do
it 'get current regular match' do
expect(schedule.regular_now).to include('start_time')
expect(schedule.regular_now.stages.count).to be(2)
end
end

describe "#bankara_open_next" do
it "get next bankara open match" do
expect(schedule.bankara_open_next).to include("start_time")
describe '#bankara_open_next' do
it 'get next bankara open match' do
expect(schedule.bankara_open_next).to include('start_time')
expect(schedule.bankara_open_next.stages.count).to be(2)
end
end

describe "#salmon_run_now" do
it "get current salmon run" do
expect(schedule.salmon_run_now).to include("start_time")
describe '#salmon_run_now' do
it 'get current salmon run' do
expect(schedule.salmon_run_now).to include('start_time')
expect(schedule.salmon_run_now.weapons.count).to be(4)
end
end
Expand Down
42 changes: 22 additions & 20 deletions spec/ika3/weapons_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# frozen_string_literal: true

RSpec.describe Ika3::Weapon do
let(:weapon) {{name: weapon_name, sub: sub_name, special: special_name}}
let(:weapon_name) {'わかばシューター'}
let(:sub_name) {'スプラボム'}
let(:special_name) {'グレートバリア'}
let(:key_name) {:splattershot_jr}
let(:weapon) { { name: weapon_name, sub: sub_name, special: special_name } }
let(:weapon_name) { 'わかばシューター' }
let(:sub_name) { 'スプラボム' }
let(:special_name) { 'グレートバリア' }
let(:key_name) { :splattershot_jr }

describe "#find_by_name" do
it "get weapon info from name" do
expect(Ika3::Weapon.find_by_name(weapon_name)).to eq weapon
describe '#find_by_name' do
it 'get weapon info from name' do
expect(described_class.find_by_name(weapon_name)).to eq weapon
end
end

describe "#filter_by_sub" do
it "get weapon info list from sub weapon" do
expect(Ika3::Weapon.filter_by_sub(sub_name)).to include weapon
describe '#filter_by_sub' do
it 'get weapon info list from sub weapon' do
expect(described_class.filter_by_sub(sub_name)).to include weapon
end
end

describe "#name" do
it "get weapon name" do
expect(Ika3::Weapon.find(key_name).name).to eq weapon_name
describe '#name' do
it 'get weapon name' do
expect(described_class.find(key_name).name).to eq weapon_name
end
end

describe "#sub" do
it "get sub weapon name" do
expect(Ika3::Weapon.find(key_name).sub).to eq sub_name
describe '#sub' do
it 'get sub weapon name' do
expect(described_class.find(key_name).sub).to eq sub_name
end
end

describe "#special" do
it "get special name" do
expect(Ika3::Weapon.find(key_name).special).to eq special_name
describe '#special' do
it 'get special name' do
expect(described_class.find(key_name).special).to eq special_name
end
end
end
4 changes: 2 additions & 2 deletions spec/ika3_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Ika3 do
it "has a version number" do
expect(Ika3::VERSION).not_to be nil
it 'has a version number' do
expect(Ika3::VERSION).not_to be_nil
end
end
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require "ika3"
require 'ika3'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
config.example_status_persistence_file_path = '.rspec_status'

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
Expand Down

0 comments on commit 8e55911

Please sign in to comment.