lol_data_fetcher 0.2.0 → 0.3.0

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: 7cf99a663e6a86de3bb2bab4aa9a2237dbe6a6fb4400429f0c0866c605472426
4
- data.tar.gz: c99bb67f229a840db389e1324ace988992d8768b402d43cb5c4c913d595c36e7
3
+ metadata.gz: 84b940340e873c546e540b47349ceb1cae28e4503fbc0f4056226dd2d2cfe2d7
4
+ data.tar.gz: 5bd9d64f06def02eb3c70e168be0d2825cfcb61ec377a6296470a119abfcb15d
5
5
  SHA512:
6
- metadata.gz: fbf7a156f906d9b9c2182da7c9e9da80a91acadfee7870b9cda9f7c2628ac928ebace11345d589303e47aff524919c22ba98d328ae134337044eeb31778ded02
7
- data.tar.gz: 69f2a49fe2999c5706f50a9bc2b989e126ee5b3aee5158658e230c50bfa7e5b64499747a2d45b137fa69f0be6a465d627ffcaa2e5b04bc323dd17a141219b8d2
6
+ metadata.gz: fe02fd0be3d0413f3954143702624fc0e3c96e55cacb2c6376ebf2b72220bcc57c78fb10322060b2c6cd6438b5139d5a924ed8546a3c0c870b2729a44ac80934
7
+ data.tar.gz: 2bed146707485387697355cd10d51fecfb4f69c385f002062f306ceffeb5c1fea674f84b539b87a40188d77dbdf959706c09ef9961c7330557d2a555f2416933
data/README.md CHANGED
@@ -7,6 +7,7 @@ A Ruby client for the League of Legends Data Dragon API. Fetch champions, items,
7
7
  - Fetch all champions with detailed information including skills/spells
8
8
  - Get all items and search by name
9
9
  - Retrieve champion skins with image URLs
10
+ - **Case-insensitive search** for champions, items, and skins
10
11
  - Support for multiple game versions and languages
11
12
  - Command-line interface (CLI) for quick data access
12
13
  - Comprehensive test coverage with RSpec
@@ -67,12 +68,17 @@ ahri_data = ahri["data"]["Ahri"]
67
68
  puts ahri_data["name"] # => "Ahri"
68
69
  puts ahri_data["title"] # => "the Nine-Tailed Fox"
69
70
 
71
+ # Case-insensitive search (works with any casing!)
72
+ client.champions.find("ahri") # => Works!
73
+ client.champions.find("AHRI") # => Works!
74
+ client.champions.find("DrAvEn") # => Works!
75
+
70
76
  # Access champion's passive ability
71
77
  passive = ahri_data["passive"]
72
78
  puts "#{passive['name']}: #{passive['description']}"
73
79
 
74
- # Or use the helper method
75
- passive = client.champions.passive("Ahri")
80
+ # Or use the helper method (also case-insensitive)
81
+ passive = client.champions.passive("ahri")
76
82
  puts "#{passive['name']}: #{passive['description']}"
77
83
 
78
84
  # Access champion spells/skills
@@ -101,8 +107,12 @@ end
101
107
  boots = client.items.find("1001")
102
108
  puts boots["name"] # => "Boots"
103
109
 
104
- # Search items by name
105
- swords = client.items.search("sword")
110
+ # Find item by name (case-insensitive exact match)
111
+ boots = client.items.find_by_name("boots") # Works with any casing
112
+ puts boots["name"] # => "Boots"
113
+
114
+ # Search items by name (case-insensitive partial match)
115
+ swords = client.items.search("SWORD") # Case doesn't matter
106
116
  swords.each do |item|
107
117
  puts item["name"]
108
118
  end
@@ -114,8 +124,8 @@ ids = client.items.list_ids
114
124
  #### Fetching Skins
115
125
 
116
126
  ```ruby
117
- # Get all skins for a specific champion
118
- skins = client.skins.for_champion("Ahri")
127
+ # Get all skins for a specific champion (case-insensitive)
128
+ skins = client.skins.for_champion("ahri") # Works with any casing
119
129
  skins.each do |skin|
120
130
  puts skin["name"]
121
131
  puts "Splash: #{skin['splash_url']}"
@@ -272,27 +282,34 @@ client = LolDataFetcher::Client.new(version: "15.23.1", language: "en_US")
272
282
 
273
283
  ### Champions Resource
274
284
 
285
+ All champion name searches are **case-insensitive**.
286
+
275
287
  ```ruby
276
288
  client.champions.all # Get all champions (overview)
277
- client.champions.find("Ahri") # Get detailed champion data
278
- client.champions.passive("Ahri") # Get champion's passive ability
289
+ client.champions.find("ahri") # Get detailed champion data (case-insensitive)
290
+ client.champions.passive("AHRI") # Get champion's passive ability (case-insensitive)
279
291
  client.champions.list_names # List all champion names
280
292
  client.champions.find_by_id("103") # Find champion by ID
281
293
  ```
282
294
 
283
295
  ### Items Resource
284
296
 
297
+ Item searches are **case-insensitive**.
298
+
285
299
  ```ruby
286
300
  client.items.all # Get all items
287
301
  client.items.find("1001") # Find item by ID
302
+ client.items.find_by_name("boots") # Find item by name (case-insensitive)
288
303
  client.items.list_ids # List all item IDs
289
- client.items.search("sword") # Search items by name
304
+ client.items.search("SWORD") # Search items by name (case-insensitive)
290
305
  ```
291
306
 
292
307
  ### Skins Resource
293
308
 
309
+ Champion name searches are **case-insensitive**.
310
+
294
311
  ```ruby
295
- client.skins.for_champion("Ahri") # Get skins for a champion
312
+ client.skins.for_champion("ahri") # Get skins for a champion (case-insensitive)
296
313
  ```
297
314
 
298
315
  ### Versions Resource
@@ -51,7 +51,10 @@ module LolDataFetcher
51
51
  client = create_client
52
52
  data = client.champions.find(name)
53
53
 
54
- champion_data = data.dig("data", name)
54
+ # Extract the normalized champion name from the response
55
+ normalized_name = data.dig("data")&.keys&.first
56
+ champion_data = data.dig("data", normalized_name)
57
+
55
58
  unless champion_data
56
59
  error("Champion '#{name}' not found")
57
60
  return
@@ -130,7 +133,12 @@ module LolDataFetcher
130
133
  client = create_client
131
134
  skins = client.skins.for_champion(champion_name)
132
135
 
133
- puts "\n#{champion_name}'s Skins:"
136
+ # Get the correctly-cased champion name from the first skin's URL if available
137
+ # Or fetch it directly from the champions resource
138
+ champion_data = client.champions.find(champion_name)
139
+ normalized_name = champion_data.dig("data")&.keys&.first || champion_name
140
+
141
+ puts "\n#{normalized_name}'s Skins:"
134
142
  puts "=" * 50
135
143
 
136
144
  skins.each do |skin|
@@ -11,17 +11,23 @@ module LolDataFetcher
11
11
  end
12
12
 
13
13
  # Fetch detailed data for a specific champion including skills
14
- # @param name [String] Champion name (e.g., "Ahri", "MasterYi")
14
+ # Supports case-insensitive search (e.g., "ahri", "AHRI", "Ahri")
15
+ # @param name [String] Champion name (case-insensitive)
15
16
  # @return [Hash] Detailed champion data including spells/skills
16
17
  def find(name)
17
- get(cdn_path("champion/#{name}"))
18
+ normalized_name = normalize_name(name)
19
+ data = get(cdn_path("champion/#{normalized_name}"))
20
+ # Return data with the normalized name key
21
+ data
18
22
  end
19
23
 
20
24
  # Get passive ability for a specific champion
21
- # @param name [String] Champion name (e.g., "Ahri", "MasterYi")
25
+ # Supports case-insensitive search
26
+ # @param name [String] Champion name (case-insensitive)
22
27
  # @return [Hash, nil] Passive ability data or nil if not found
23
28
  def passive(name)
24
- find(name).dig("data", name, "passive")
29
+ normalized_name = normalize_name(name)
30
+ find(normalized_name).dig("data", normalized_name, "passive")
25
31
  end
26
32
 
27
33
  # List all champion names
@@ -36,6 +42,33 @@ module LolDataFetcher
36
42
  def find_by_id(id)
37
43
  all.dig("data")&.find { |_key, champ| champ["key"] == id.to_s }&.last
38
44
  end
45
+
46
+ private
47
+
48
+ # Normalize champion name to match Data Dragon API casing
49
+ # Performs case-insensitive lookup to find the correct champion name
50
+ # @param name [String] Champion name in any casing
51
+ # @return [String] Properly-cased champion name for API
52
+ # @raise [NotFoundError] If champion is not found
53
+ def normalize_name(name)
54
+ return name if name.nil? || name.empty?
55
+
56
+ # Get all champion names from the API
57
+ champions_data = all.dig("data")
58
+ return name unless champions_data
59
+
60
+ # Find the champion with case-insensitive matching
61
+ normalized = champions_data.keys.find do |champion_name|
62
+ champion_name.downcase == name.downcase
63
+ end
64
+
65
+ # If not found, raise an error
66
+ unless normalized
67
+ raise NotFoundError, "Champion '#{name}' not found. Check spelling and try again."
68
+ end
69
+
70
+ normalized
71
+ end
39
72
  end
40
73
  end
41
74
  end
@@ -23,13 +23,21 @@ module LolDataFetcher
23
23
  all.dig("data")&.keys || []
24
24
  end
25
25
 
26
- # Search items by name
27
- # @param query [String] Search query
26
+ # Search items by name (case-insensitive)
27
+ # @param query [String] Search query (case-insensitive)
28
28
  # @return [Array<Hash>] Array of matching items
29
29
  def search(query)
30
30
  items = all.dig("data") || {}
31
31
  items.select { |_id, item| item["name"]&.downcase&.include?(query.downcase) }.values
32
32
  end
33
+
34
+ # Find item by exact name match (case-insensitive)
35
+ # @param name [String] Item name (case-insensitive)
36
+ # @return [Hash, nil] Item data or nil if not found
37
+ def find_by_name(name)
38
+ items = all.dig("data") || {}
39
+ items.find { |_id, item| item["name"]&.downcase == name.downcase }&.last
40
+ end
33
41
  end
34
42
  end
35
43
  end
@@ -5,19 +5,27 @@ module LolDataFetcher
5
5
  # Resource for fetching champion skin data
6
6
  class Skins < Base
7
7
  # Fetch skins for a specific champion
8
- # @param champion_name [String] Champion name (e.g., "Ahri")
8
+ # Supports case-insensitive search (e.g., "ahri", "AHRI", "Ahri")
9
+ # @param champion_name [String] Champion name (case-insensitive)
9
10
  # @return [Array<Hash>] Array of skin data with image URLs
10
11
  def for_champion(champion_name)
11
- champion_data = get(cdn_path("champion/#{champion_name}"))
12
- skins = champion_data.dig("data", champion_name, "skins") || []
12
+ # Use the champions resource to get the data with normalized name
13
+ champion_data = client.champions.find(champion_name)
14
+
15
+ # The find method returns data with the normalized name as key
16
+ # We need to extract that key from the data
17
+ normalized_name = champion_data.dig("data")&.keys&.first
18
+ return [] unless normalized_name
19
+
20
+ skins = champion_data.dig("data", normalized_name, "skins") || []
13
21
 
14
22
  skins.map do |skin|
15
23
  {
16
24
  "id" => skin["id"],
17
25
  "num" => skin["num"],
18
26
  "name" => skin["name"],
19
- "splash_url" => splash_url(champion_name, skin["num"]),
20
- "loading_url" => loading_url(champion_name, skin["num"]),
27
+ "splash_url" => splash_url(normalized_name, skin["num"]),
28
+ "loading_url" => loading_url(normalized_name, skin["num"]),
21
29
  "chromas" => skin["chromas"] || false
22
30
  }
23
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LolDataFetcher
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_data_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Chavez