ygoprodeck 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7b8e5947a55893879f833bb1c573581a1debaacd252719387115e5e8d80c52c
4
- data.tar.gz: d5f68bbfccb2a899f822cdf4742db3bbcc3ac80651ebc9c7b56e16483de02a11
3
+ metadata.gz: 38c1e28c30e9912a0d3f532d69d0bb19f13496041c7aefa4722d57bb461dc3d6
4
+ data.tar.gz: a701b1fcfc477cfe6d4c6444efdc94d790e22ec0b45ba3079205da8e0cb557c7
5
5
  SHA512:
6
- metadata.gz: 3f5ce7c3509147d7d1eb318449af73ccc5724c9445ddd91c1554d4c56d12a2eab985f318164bc32f9c560ac8846a736e11f12360a32dc6004f036513241b0311
7
- data.tar.gz: 3e3dcf4a3907d631579aaa30069fef46c0d633012c85ee89e797ad3f9726ba5d1e28d6206c73d469732702af1d6a138ad1240300c66f1e4198e3a1b745deed17
6
+ metadata.gz: 585feb7a99dd8cc41a84b69132a698261ecd78a3c13dadfd1b37e9557a436b6a16703d0a9291ea11de23b4fd4dd68d0efa72a7a91dd947b659a5644c93f7bdcf
7
+ data.tar.gz: 8e67e92b923bf9d172175cd709b6eb1390ca9f52f67ff89a114ae8d06a14998dddac336ce15b20190810a6c4c83e369664179f1cd98512ad5f0a8154a47740c8
data/.rubocop.yml CHANGED
@@ -1,4 +1,6 @@
1
- inherit_from: .rubocop_todo.yml
1
+ require:
2
+ - rubocop-performance
3
+
2
4
  AllCops:
3
5
  Include:
4
6
  - "**/*.rb"
@@ -7,4 +9,61 @@ AllCops:
7
9
  Exclude:
8
10
  - "vendor/**/*"
9
11
  - "db/schema.rb"
12
+ - Gemfile
13
+ - Rakefile
14
+ - "*.gemspec"
10
15
  NewCops: enable
16
+
17
+ Performance:
18
+ Enabled: true
19
+
20
+ Layout/LineLength:
21
+ Enabled: false
22
+
23
+ Style/BlockDelimiters:
24
+ Enabled: false
25
+
26
+ Lint/AmbiguousBlockAssociation:
27
+ Enabled: false
28
+
29
+ Metrics/BlockLength:
30
+ Enabled: false
31
+
32
+ Layout/HeredocIndentation:
33
+ Enabled: false
34
+
35
+ Metrics/ClassLength:
36
+ Enabled: false
37
+
38
+ Metrics/MethodLength:
39
+ Enabled: false
40
+
41
+ Metrics/ParameterLists:
42
+ Enabled: false
43
+
44
+ Metrics/AbcSize:
45
+ Enabled: false
46
+
47
+ Metrics/PerceivedComplexity:
48
+ Enabled: false
49
+
50
+ Metrics/CyclomaticComplexity:
51
+ Enabled: false
52
+
53
+ Style/HashEachMethods:
54
+ Enabled: true
55
+
56
+ Style/HashTransformKeys:
57
+ Enabled: false
58
+
59
+ Style/HashTransformValues:
60
+ Enabled: false
61
+
62
+ Style/FrozenStringLiteralComment:
63
+ Enabled: false
64
+
65
+ Style/Documentation:
66
+ Enabled: false
67
+
68
+ Style/StringLiterals:
69
+ Enabled: false
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  gemspec name: 'ygoprodeck'
4
4
 
5
5
  gem 'rubocop', '1.80.0'
6
+ gem 'rubocop-performance', '1.26.0'
data/examples/banlist.rb CHANGED
@@ -3,3 +3,4 @@ require "ygoprodeck"
3
3
  puts Ygoprodeck::Banlist.tcg
4
4
  #puts Ygoprodeck::Banlist.ocg
5
5
  #puts Ygoprodeck::Banlist.goat
6
+ #puts Ygoprodeck::Banlist.md
data/examples/search.rb CHANGED
@@ -3,8 +3,7 @@ require "ygoprodeck"
3
3
  # yugi is example, you free to change name card
4
4
  yugi = Ygoprodeck::Name.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
5
5
 
6
- case
7
- when yugi == nil
6
+ if yugi.nil?
8
7
  puts "Card not found"
9
8
  else
10
9
  puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
@@ -1,26 +1,25 @@
1
- require "ygoprodeck"
2
-
3
- # yugi is example, you free to change name card
4
- yugi = Ygoprodeck::Fname.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
5
-
6
- case
7
- when yugi == nil
8
- puts "Card not found"
9
- else
10
- puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
11
-
12
- puts "#" * 10
13
-
14
- # => get specific information of dark magician
15
- puts yugi["id"]
16
- puts yugi["name"]
17
- puts yugi["attribute"]
18
- puts yugi["type"]
19
- puts yugi["race"]
20
- puts yugi["level"]
21
- puts yugi["desc"]
22
- puts yugi["atk"]
23
- puts yugi["def"]
24
- puts Ygoprodeck::Image.is(yugi["id"]) # => use id from yugi['id'] to get dark magician image
25
- puts Ygoprodeck::Image_small.is(yugi["id"]) # => small version
26
- end
1
+ require "ygoprodeck"
2
+
3
+ # yugi is example, you free to change name card
4
+ yugi = Ygoprodeck::Fname.is("dark magician") # example I wanna search 'dark magician' using fuzzy search
5
+
6
+ if yugi.nil?
7
+ puts "Card not found"
8
+ else
9
+ puts yugi # => get all information of dark magician (name,id,level,attr,atk,def,etc)
10
+
11
+ puts "#" * 10
12
+
13
+ # => get specific information of dark magician
14
+ puts yugi["id"]
15
+ puts yugi["name"]
16
+ puts yugi["attribute"]
17
+ puts yugi["type"]
18
+ puts yugi["race"]
19
+ puts yugi["level"]
20
+ puts yugi["desc"]
21
+ puts yugi["atk"]
22
+ puts yugi["def"]
23
+ puts Ygoprodeck::Image.is(yugi["id"]) # => use id from yugi['id'] to get dark magician image
24
+ puts Ygoprodeck::Image_small.is(yugi["id"]) # => small version
25
+ end
@@ -1,3 +1,3 @@
1
- module Ygoprodeck
2
- class Error < StandardError; end
3
- end
1
+ module Ygoprodeck
2
+ class Error < StandardError; end
3
+ end
@@ -1,2 +1,2 @@
1
- #
2
- # sorry I did't created get all card, because you need 2 days to get all card
1
+ #
2
+ # sorry I did't created get all card, because you need 2 days to get all card
@@ -1,30 +1,26 @@
1
- module Ygoprodeck
2
- class Archetype
3
- attr_reader :archetype
4
-
5
- def self.is(archetype)
6
- url =
7
- "#{Ygoprodeck::Endpoint.is}cardinfo.php?archetype=#{URI.encode_www_form_component(archetype)}"
8
- uri = URI(url)
9
-
10
- begin
11
- response = Net::HTTP.get(uri)
12
- load = JSON.parse(response)
13
-
14
- if load["data"].nil? || load["data"].empty?
15
- {
16
- "error" => "No card matching your query was found in the database."
17
- }
18
- else
19
- load["data"]
20
- end
21
- rescue JSON::ParserError => e
22
- { "error" => "Failed to parse JSON response" }
23
- rescue SocketError => e
24
- { "error" => "Network connection error" }
25
- rescue StandardError => e
26
- { "error" => "An unexpected error occurred: #{e.message}" }
27
- end
28
- end
29
- end
30
- end
1
+ module Ygoprodeck
2
+ class Archetype
3
+ attr_reader :archetype
4
+
5
+ def self.is(archetype)
6
+ url =
7
+ "#{Ygoprodeck::Endpoint.is}cardinfo.php?archetype=#{URI.encode_www_form_component(archetype)}&format=genesys&misc=yes"
8
+ uri = URI(url)
9
+
10
+ begin
11
+ response = Net::HTTP.get(uri)
12
+ load = JSON.parse(response)
13
+
14
+ if load["data"].nil? || load["data"].empty?
15
+ {
16
+ "error" => "No card matching your query was found in the database."
17
+ }
18
+ else
19
+ load["data"]
20
+ end
21
+ rescue StandardError
22
+ { "error" => "Something went wrong" }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,78 +1,76 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'uri'
4
-
5
- module Ygoprodeck
6
- class Banlist
7
- API_BASE = 'https://ygoprodeck.com/api/banlist'
8
-
9
- def self.fetch_banlist(format)
10
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?banlist=#{format}"
11
- uri = URI(url)
12
-
13
- begin
14
- response = Net::HTTP.get(uri)
15
- load = JSON.parse(response)
16
-
17
- if load.has_key?('error')
18
- { 'error' => load['error'] }
19
- else
20
- load
21
- end
22
- rescue JSON::ParserError
23
- { 'error' => 'Failed to parse JSON response' }
24
- rescue SocketError
25
- { 'error' => 'Network connection error' }
26
- rescue StandardError => e
27
- { 'error' => "An unexpected error occurred: #{e.message}" }
28
- end
29
- end
30
-
31
- def self.tcg
32
- fetch_banlist('tcg')
33
- end
34
-
35
- def self.ocg
36
- fetch_banlist('ocg')
37
- end
38
-
39
- def self.goat
40
- fetch_banlist('goat')
41
- end
42
-
43
- def self.md
44
-
45
- dates_uri = URI("#{API_BASE}/getBanListDates.php")
46
- dates_res = Net::HTTP.get(dates_uri)
47
- dates = JSON.parse(dates_res)
48
-
49
- master_duel_dates = dates.select { |d| d['type'] == 'Master Duel' }
50
- return { 'error' => 'No Master Duel dates found' } if master_duel_dates.empty?
51
-
52
- latest_date = master_duel_dates.map { |d| d['date'] }.max
53
-
54
- list_uri = URI("#{API_BASE}/getBanList.php?list=Master%20Duel&date=#{latest_date}")
55
- req = Net::HTTP::Get.new(list_uri)
56
- req['User-Agent'] = 'Mozilla/5.0'
57
-
58
- res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
59
- http.request(req)
60
- end
61
-
62
- load = JSON.parse(res.body)
63
-
64
- if load.is_a?(Hash) && load.key?('error')
65
- { 'error' => load['error'] }
66
- else
67
- load
68
- end
69
- rescue JSON::ParserError
70
- { 'error' => 'Failed to parse JSON response' }
71
- rescue SocketError
72
- { 'error' => 'Network connection error' }
73
- rescue StandardError => e
74
- { 'error' => "An unexpected error occurred: #{e.message}" }
75
-
76
- end
77
- end
78
- end
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module Ygoprodeck
6
+ class Banlist
7
+ API_BASE = 'https://ygoprodeck.com/api/banlist'.freeze
8
+
9
+ def self.fetch_banlist(format)
10
+ url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?banlist=#{format}"
11
+ uri = URI(url)
12
+
13
+ begin
14
+ response = Net::HTTP.get(uri)
15
+ load = JSON.parse(response)
16
+
17
+ if load.has_key?('error')
18
+ { 'error' => load['error'] }
19
+ else
20
+ load
21
+ end
22
+ rescue JSON::ParserError
23
+ { 'error' => 'Failed to parse JSON response' }
24
+ rescue SocketError
25
+ { 'error' => 'Network connection error' }
26
+ rescue StandardError => e
27
+ { 'error' => "An unexpected error occurred: #{e.message}" }
28
+ end
29
+ end
30
+
31
+ def self.tcg
32
+ fetch_banlist('tcg')
33
+ end
34
+
35
+ def self.ocg
36
+ fetch_banlist('ocg')
37
+ end
38
+
39
+ def self.goat
40
+ fetch_banlist('goat')
41
+ end
42
+
43
+ def self.md
44
+ dates_uri = URI("#{API_BASE}/getBanListDates.php")
45
+ dates_res = Net::HTTP.get(dates_uri)
46
+ dates = JSON.parse(dates_res)
47
+
48
+ master_duel_dates = dates.select { |d| d['type'] == 'Master Duel' }
49
+ return { 'error' => 'No Master Duel dates found' } if master_duel_dates.empty?
50
+
51
+ latest_date = master_duel_dates.map { |d| d['date'] }.max
52
+
53
+ list_uri = URI("#{API_BASE}/getBanList.php?list=Master%20Duel&date=#{latest_date}")
54
+ req = Net::HTTP::Get.new(list_uri)
55
+ req['User-Agent'] = 'Mozilla/5.0'
56
+
57
+ res = Net::HTTP.start(list_uri.host, list_uri.port, use_ssl: true) do |http|
58
+ http.request(req)
59
+ end
60
+
61
+ load = JSON.parse(res.body)
62
+
63
+ if load.is_a?(Hash) && load.key?('error')
64
+ { 'error' => load['error'] }
65
+ else
66
+ load
67
+ end
68
+ rescue JSON::ParserError
69
+ { 'error' => 'Failed to parse JSON response' }
70
+ rescue SocketError
71
+ { 'error' => 'Network connection error' }
72
+ rescue StandardError => e
73
+ { 'error' => "An unexpected error occurred: #{e.message}" }
74
+ end
75
+ end
76
+ end
@@ -1,28 +1,21 @@
1
- module Ygoprodeck
2
- class Card
3
- def self.sets
4
- url = "https://db.ygoprodeck.com/api/v7/cardsets.php"
5
- uri = URI(url)
6
-
7
- begin
8
- response = Net::HTTP.get(uri)
9
- load = JSON.parse(response)
10
-
11
- if load.is_a?(Hash) && load.has_key?('error')
12
- { 'error' => load['error'] }
13
- else
14
- load
15
- end
16
-
17
- rescue JSON::ParserError => e
18
- { 'error' => 'Failed to parse JSON response' }
19
- rescue SocketError => e
20
- { 'error' => 'Network connection error' }
21
- rescue Timeout::Error => e
22
- { 'error' => 'Request timed out' }
23
- rescue StandardError => e
24
- { 'error' => "An unexpected error occurred: #{e.message}" }
25
- end
26
- end
27
- end
28
- end
1
+ module Ygoprodeck
2
+ class Card
3
+ def self.sets
4
+ url = "https://db.ygoprodeck.com/api/v7/cardsets.php"
5
+ uri = URI(url)
6
+
7
+ begin
8
+ response = Net::HTTP.get(uri)
9
+ load = JSON.parse(response)
10
+
11
+ if load.is_a?(Hash) && load.has_key?('error')
12
+ { 'error' => load['error'] }
13
+ else
14
+ load
15
+ end
16
+ rescue StandardError => e
17
+ { 'error' => "An unexpected error occurred: #{e.message}" }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,33 +1,24 @@
1
- module Ygoprodeck
2
- class CheckDbVer
3
- def self.info
4
- url = "https://db.ygoprodeck.com/api/v7/checkDBVer.php"
5
- uri = URI(url)
6
-
7
- begin
8
- response = Net::HTTP.get_response(uri)
9
-
10
- unless response.is_a?(Net::HTTPSuccess)
11
- return { 'error' => "HTTP request failed with status code: #{response.code}" }
12
- end
13
-
14
- load = JSON.parse(response.body)
15
-
16
- if load.is_a?(Hash) && load.has_key?('error')
17
- { 'error' => load['error'] }
18
- else
19
- load
20
- end
21
-
22
- rescue JSON::ParserError => e
23
- { 'error' => 'Failed to parse JSON response' }
24
- rescue SocketError => e
25
- { 'error' => 'Network connection error' }
26
- rescue Net::ReadTimeout => e
27
- { 'error' => 'Request timed out' }
28
- rescue StandardError => e
29
- { 'error' => "An unexpected error occurred: #{e.message}" }
30
- end
31
- end
32
- end
33
- end
1
+ module Ygoprodeck
2
+ class CheckDbVer
3
+ def self.info
4
+ url = "https://db.ygoprodeck.com/api/v7/checkDBVer.php"
5
+ uri = URI(url)
6
+
7
+ begin
8
+ response = Net::HTTP.get_response(uri)
9
+
10
+ return { 'error' => "HTTP request failed with status code: #{response.code}" } unless response.is_a?(Net::HTTPSuccess)
11
+
12
+ load = JSON.parse(response.body)
13
+
14
+ if load.is_a?(Hash) && load.has_key?('error')
15
+ { 'error' => load['error'] }
16
+ else
17
+ load
18
+ end
19
+ rescue StandardError => e
20
+ { 'error' => "An unexpected error occurred: #{e.message}" }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,8 +1,7 @@
1
-
2
- module Ygoprodeck
3
- class Endpoint
4
- def self.is
5
- "https://db.ygoprodeck.com/api/v7/"
6
- end
7
- end
8
- end
1
+ module Ygoprodeck
2
+ class Endpoint
3
+ def self.is
4
+ "https://db.ygoprodeck.com/api/v7/"
5
+ end
6
+ end
7
+ end
@@ -1,16 +1,17 @@
1
-
2
- module Ygoprodeck
3
- class Image
4
- attr_reader :image_by_id
5
- def self.is(image_by_id)
6
- "https://images.ygoprodeck.com/images/cards/#{image_by_id}.jpg"
7
- end
8
- end
9
-
10
- class Image_small
11
- attr_reader :image_small_by_id
12
- def self.is(image_small_by_id)
13
- "https://images.ygoprodeck.com/images/cards_cropped/#{image_small_by_id}.jpg"
14
- end
15
- end
16
- end
1
+ module Ygoprodeck
2
+ class Image
3
+ attr_reader :image_by_id
4
+
5
+ def self.is(image_by_id)
6
+ "https://images.ygoprodeck.com/images/cards/#{image_by_id}.jpg"
7
+ end
8
+ end
9
+
10
+ class Image_small
11
+ attr_reader :image_small_by_id
12
+
13
+ def self.is(image_small_by_id)
14
+ "https://images.ygoprodeck.com/images/cards_cropped/#{image_small_by_id}.jpg"
15
+ end
16
+ end
17
+ end
@@ -1,20 +1,21 @@
1
- module Ygoprodeck
2
- class Fname
3
- def self.is(f_name)
4
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(f_name)}"
5
- uri = URI(url)
6
-
7
- begin
8
- response = Net::HTTP.get(uri)
9
- load = JSON.parse(response)
10
-
11
- return nil if load["data"].nil? || load["data"].empty?
12
-
13
- load["data"][0]
14
-
15
- rescue JSON::ParserError, SocketError, StandardError => e
16
- nil
17
- end
18
- end
19
- end
20
- end
1
+ module Ygoprodeck
2
+ class Fname
3
+ attr_reader :f_name
4
+
5
+ def self.is(f_name)
6
+ url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(f_name)}&format=genesys&misc=yes"
7
+ uri = URI(url)
8
+
9
+ begin
10
+ response = Net::HTTP.get(uri)
11
+ load = JSON.parse(response)
12
+
13
+ return nil if load["data"].nil? || load["data"].empty?
14
+
15
+ load["data"][0]
16
+ rescue StandardError
17
+ { "error" => "Something went wrong" }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,7 @@
1
1
  module Ygoprodeck
2
2
  class ID
3
3
  def self.is(id)
4
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?id=#{(id)}"
4
+ url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?id=#{id}"
5
5
  uri = URI(url)
6
6
 
7
7
  begin
@@ -11,8 +11,8 @@ module Ygoprodeck
11
11
  return nil if load["data"].nil? || load["data"].empty?
12
12
 
13
13
  load["data"][0]
14
- rescue JSON::ParserError, SocketError, StandardError => e
15
- nil
14
+ rescue StandardError
15
+ { "error" => "Something went wrong" }
16
16
  end
17
17
  end
18
18
  end
@@ -1,47 +1,34 @@
1
- module Ygoprodeck
2
- class List
3
- attr_reader :list
4
-
5
- def self.is(list)
6
- begin
7
- # Encode query parameter to handle special characters properly
8
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(list)}"
9
- uri = URI(url)
10
-
11
- # Use timeout to prevent hanging on slow connections
12
- response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', open_timeout: 10, read_timeout: 10) do |http|
13
- http.get(uri.request_uri)
14
- end
15
-
16
- # Check HTTP status code first
17
- case response
18
- when Net::HTTPSuccess
19
- load = JSON.parse(response.body)
20
-
21
- if load.has_key?('error')
22
- return { 'error' => load['error'] }
23
- elsif load['data'].nil? || load['data'].empty?
24
- return { 'error' => 'No card matching your query was found in the database.' }
25
- else
26
- return load['data']
27
- end
28
- else
29
- return { 'error' => "HTTP request failed with status code: #{response.code}" }
30
- end
31
-
32
- rescue URI::InvalidURIError => e
33
- { 'error' => 'Invalid URL or search term' }
34
- rescue JSON::ParserError => e
35
- { 'error' => 'Failed to parse JSON response' }
36
- rescue Net::OpenTimeout => e
37
- { 'error' => 'Connection timed out' }
38
- rescue Net::ReadTimeout => e
39
- { 'error' => 'Request timed out' }
40
- rescue SocketError => e
41
- { 'error' => 'Network connection error' }
42
- rescue StandardError => e
43
- { 'error' => "An unexpected error occurred: #{e.message}" }
44
- end
45
- end
46
- end
47
- end
1
+ module Ygoprodeck
2
+ class List
3
+ attr_reader :list
4
+
5
+ def self.is(list)
6
+ # Encode query parameter to handle special characters properly
7
+ url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?fname=#{URI.encode_www_form_component(list)}&format=genesys&misc=yes"
8
+ uri = URI(url)
9
+
10
+ # Use timeout to prevent hanging on slow connections
11
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', open_timeout: 10, read_timeout: 10) do |http|
12
+ http.get(uri.request_uri)
13
+ end
14
+
15
+ # Check HTTP status code first
16
+ case response
17
+ when Net::HTTPSuccess
18
+ load = JSON.parse(response.body)
19
+
20
+ if load.has_key?('error')
21
+ { 'error' => load['error'] }
22
+ elsif load['data'].nil? || load['data'].empty?
23
+ { 'error' => 'No card matching your query was found in the database.' }
24
+ else
25
+ load['data']
26
+ end
27
+ else
28
+ { 'error' => "HTTP request failed with status code: #{response.code}" }
29
+ end
30
+ rescue StandardError => e
31
+ { 'error' => "An unexpected error occurred: #{e.message}" }
32
+ end
33
+ end
34
+ end
@@ -1,7 +1,7 @@
1
1
  module Ygoprodeck
2
2
  class Match
3
3
  def self.normalize(text)
4
- text.downcase.gsub(/[^a-z0-9\s\-]/, '').strip
4
+ text.downcase.gsub(/[^a-z0-9\s-]/, '').strip
5
5
  end
6
6
 
7
7
  def self.is(name_card)
@@ -13,23 +13,23 @@ module Ygoprodeck
13
13
 
14
14
  substring_matches = names.select { |name| normalize(name).include?(normalized_input) }
15
15
 
16
- if !substring_matches.empty?
17
- best_match = substring_matches.min_by { |name| normalize(name).length }
18
- else
16
+ if substring_matches.empty?
19
17
  word_matches = names.select do |name|
20
18
  name_words = normalize(name).split
21
19
  input_words.all? { |word| name_words.any? { |nw| nw.include?(word) } }
22
20
  end
23
21
 
24
- if !word_matches.empty?
25
- best_match = word_matches.min_by { |name| normalize(name).length }
26
- else
22
+ if word_matches.empty?
27
23
  matcher = Levenshtein.new(normalized_input)
28
24
  best_match = names.min_by { |name| matcher.match(normalize(name)) }
25
+ else
26
+ best_match = word_matches.min_by { |name| normalize(name).length }
29
27
  end
28
+ else
29
+ best_match = substring_matches.min_by { |name| normalize(name).length }
30
30
  end
31
31
 
32
32
  best_match
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -1,22 +1,21 @@
1
- module Ygoprodeck
2
- class Name
3
- attr_reader :name
4
-
5
- def self.is(name)
6
- url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?name=#{URI.encode_www_form_component(name)}"
7
- uri = URI(url)
8
-
9
- begin
10
- response = Net::HTTP.get(uri)
11
- load = JSON.parse(response)
12
-
13
- return nil if load["data"].nil? || load["data"].empty?
14
-
15
- load["data"][0]
16
-
17
- rescue JSON::ParserError, SocketError, StandardError => e
18
- nil
19
- end
20
- end
21
- end
22
- end
1
+ module Ygoprodeck
2
+ class Name
3
+ attr_reader :name
4
+
5
+ def self.is(name)
6
+ url = "#{Ygoprodeck::Endpoint.is}cardinfo.php?name=#{URI.encode_www_form_component(name)}&format=genesys&misc=yes"
7
+ uri = URI(url)
8
+
9
+ begin
10
+ response = Net::HTTP.get(uri)
11
+ load = JSON.parse(response)
12
+
13
+ return nil if load["data"].nil? || load["data"].empty?
14
+
15
+ load["data"][0]
16
+ rescue StandardError
17
+ { "error" => "Something went wrong" }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,20 +1,19 @@
1
- module Ygoprodeck
2
- class Card
3
- def self.random
4
- url = "https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust"
5
- uri = URI(url)
6
-
7
- begin
8
- response = Net::HTTP.get(uri)
9
- load = JSON.parse(response)
10
-
11
- return nil if load["data"].nil? || load["data"].empty?
12
-
13
- load["data"][0]
14
-
15
- rescue JSON::ParserError, SocketError, StandardError => e
16
- nil
17
- end
18
- end
19
- end
20
- end
1
+ module Ygoprodeck
2
+ class Card
3
+ def self.random
4
+ url = "https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust&format=genesys&misc=yes"
5
+ uri = URI(url)
6
+
7
+ begin
8
+ response = Net::HTTP.get(uri)
9
+ load = JSON.parse(response)
10
+
11
+ return nil if load["data"].nil? || load["data"].empty?
12
+
13
+ load["data"][0]
14
+ rescue StandardError
15
+ { "error" => "Something went wrong" }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
- module Ygoprodeck
2
- VERSION = "1.1.0"
3
- end
1
+ module Ygoprodeck
2
+ VERSION = "1.2.1".freeze
3
+ end
data/lib/ygoprodeck.rb CHANGED
@@ -1,10 +1,10 @@
1
- require "open-uri"
2
- require "net/http"
3
- require "json"
4
- require "amatch"
5
- include Amatch
6
-
7
- Dir[File.join(__dir__, "ygoprodeck/**/*.rb")].sort.each { |f| require f }
8
-
9
- module Ygoprodeck
10
- end
1
+ require "open-uri"
2
+ require "net/http"
3
+ require "json"
4
+ require "amatch"
5
+ include Amatch
6
+
7
+ Dir[File.join(__dir__, "ygoprodeck/**/*.rb")].sort.each { |f| require f }
8
+
9
+ module Ygoprodeck
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ygoprodeck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rokhimin Wahid
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.7.1
174
+ rubygems_version: 4.0.1
175
175
  specification_version: 4
176
176
  summary: ygoprodeck API wrapper for search yugioh's card
177
177
  test_files: []