smogon_dex 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/smogon_dex +33 -15
  3. data/lib/smogon_dex.rb +16 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03af9b0e4de40c1faa5b2b0d4a453d5e49bc8803
4
- data.tar.gz: 6047db50b007ff49f9bdb4bd8b11c67152593c56
3
+ metadata.gz: 616a7c4d2d855b51ba2b4ecd98cf8c6414c20f6f
4
+ data.tar.gz: 2a6d9065e956e4db1904bab15184f2ca5fc3b0af
5
5
  SHA512:
6
- metadata.gz: c145caebccf5740d54450900371b6abce52d643bf98ab7c85814fa813102adfae11fdec119af84742243f46d991bc4edfc3aa72c0de0cbbacac1f6532a702dec
7
- data.tar.gz: 3344dc5cbdd4456133018b74ded798901dc48cb2c58f734dd59304dfd5ee4606b4939d009e60672e68360cdcdd1dcd9fa8799b89f922d905f7a3ce2efe8500d1
6
+ metadata.gz: 6d4d42edc4a09911a02cad12bf223dcaf78e1f5bdd14a9183328dcc9b2eb02569cf1227cafe3481c449a0f8f205dd567d5914f2118244e53fd05218db2a6f71c
7
+ data.tar.gz: da3298962ea4b685e5665cc9023a3433549b2ee0962e4ca4682dd31f86a9ce389e51512b3261a00e74d60390ac478d2588b85ea3ecba7aa478529a3f309f6286
@@ -2,26 +2,44 @@
2
2
  require "launchy"
3
3
  require "smogon_dex"
4
4
  include SmogonDex
5
- gen, search_catagory = nil
5
+ $gen, $catagory = nil
6
6
 
7
- ARGV.each do |arg|
8
- Generations.each do |generation|
9
- if arg == "--#{generation}" and gen.nil?
10
- gen = generation
11
- ARGV.delete arg
7
+ ARGV.each do |given|
8
+ done = false
9
+ if given =~ /\A\-\-/
10
+ arg = given.gsub /\A\-\-/, ""
11
+ if arg == "home"
12
+ homepage
13
+ exit
12
14
  end
13
- end
14
- Catagories.each do |catagory|
15
- if arg == "--#{catagory}" and search_catagory.nil?
16
- search_catagory = catagory
17
- ARGV.delete arg
15
+ Generations.each do |generation|
16
+ if arg == generation and $gen.nil?
17
+ $gen, done = generation, true
18
+ break
19
+ end
20
+ end
21
+ Catagories.each do |catagory|
22
+ if arg == catagory and $catagory.nil?
23
+ $catagory = catagory
24
+ break
25
+ end
26
+ end unless done
27
+ elsif given =~ /\A\-/ and $catagory.nil?
28
+ $catagory = case given
29
+ when /a/ then "abilities"
30
+ when /m/ then "moves"
31
+ when /p/ then "pokemon"
32
+ when /i/ then "items"
33
+ when /f/ then "formats"
34
+ when /t/ then "types"
35
+ else raise "unknown switch: #{given}"
18
36
  end
37
+ elsif $query.nil?
38
+ $query = given
39
+ else warn "Unknown argument: #{given}"
19
40
  end
20
41
  end
21
- query = ARGV.shift unless ARGV.empty?
22
- search_catagory ||= "pokemon"
23
- gen ||= "xy"
24
- Launchy.open url(gen, search_catagory, query)
42
+ search(gen: $gen, catagory: $catagory, query: $query)
25
43
 
26
44
 
27
45
 
@@ -1,8 +1,22 @@
1
+ require "launchy"
1
2
  module SmogonDex
2
3
  Catagories = %w(pokemon moves abilities items formats types)
3
4
  Generations = %w(xy dp gs bw rb rs)
5
+
6
+ GEN_ARGS = Generations.map {|gen| "--#{gen}"}
7
+ CAT_ARGS = Catagories.map {|catagory| "-#{catagory}"}
8
+
4
9
  module_function
5
- def url(gen="xy", search_catagory="pokemon", query="")
6
- "https://www.smogon.com/dex/" + gen + "/" + search_catagory + "/" + query
10
+ def search(data=Hash.new)
11
+ data[:gen] ||= "xy"
12
+ data[:catagory] ||= "pokemon"
13
+ data[:query] ||= String.new
14
+
15
+ raise ArgumentError, "#{data[:gen]} is not a valid generation" unless Generations.include? data[:gen]
16
+ raise ArgumentError, "#{data[:catagory]} is not a valid catagory." unless Catagories.include? data[:catagory]
17
+ Launchy.open "https://www.smogon.com/dex/#{ data.fetch :gen }/#{ data.fetch :catagory }/#{ data.fetch :query }"
18
+ end
19
+ def homepage
20
+ Launchy.open "https://www.smogon.com/dex"
7
21
  end
8
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smogon_dex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary R. Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: launchy