haasu-sutoon-data 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e531bbd3e12f7b0c17928231a14129d4f94308dd
4
+ data.tar.gz: 2536db90711a2bf67ed8ac18b7e15132a2eb0d3f
5
+ SHA512:
6
+ metadata.gz: 46f915f021af196ee5a098c1e0f41af9f826744e6f820df48f68e58b9ee2896b5f9e869ea7e7e599365c51aef83a824c5a1327041678d2776cac7d0f358e5aae
7
+ data.tar.gz: b07b866045922ac65f04a4734a940638df50e7513b18165bff8f2482f1fd1cff5e615fbde7270f3ffa69207ca060bc5b278c741acb7fcf35a26115665d05f8c8
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,66 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-09-11 18:44:31 +0900 using RuboCop version 0.26.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ AllCops:
9
+ Exclude:
10
+ - 'bin/**/*'
11
+ - 'db/**/*'
12
+ - 'config/**/*'
13
+ - 'script/**/*'
14
+ - 'vendor/**/*'
15
+ - 'spec/spec_helper.rb'
16
+ - 'spec/rails_helper.rb'
17
+ - 'Guardfile'
18
+ - 'exe/**'
19
+
20
+ # Configuration parameters: CountComments.
21
+ Metrics/ClassLength:
22
+ Max: 500
23
+
24
+ # Configuration parameters: AllowURI.
25
+ Metrics/LineLength:
26
+ Max: 120
27
+
28
+ # Configuration parameters: CountComments.
29
+ Metrics/MethodLength:
30
+ Max: 30
31
+
32
+ Metrics/AbcSize:
33
+ Enabled: true
34
+ Max: 17
35
+
36
+ Style/AsciiComments:
37
+ Enabled: false
38
+
39
+ # Cop supports --auto-correct.
40
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
41
+ Style/BracesAroundHashParameters:
42
+ Enabled: false
43
+
44
+ Style/MultilineOperationIndentation:
45
+ Enabled: false
46
+
47
+ # Cop supports --auto-correct.
48
+ #Style/EmptyLinesAroundBody:
49
+ # Enabled: false
50
+
51
+ # Cop supports --auto-correct.
52
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
53
+ Style/SignalException:
54
+ Enabled: false
55
+
56
+ Style/WordArray:
57
+ MinSize: 10
58
+
59
+ ClassAndModuleChildren:
60
+ EnforcedStyle: compact
61
+
62
+ Style/IfUnlessModifier:
63
+ Enabled: false
64
+
65
+ Style/GuardClause:
66
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haasu-sutoon-data.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'pry-byebug'
8
+ gem 'awesome_print'
9
+ gem 'hirb'
10
+
11
+ gem 'guard-rspec'
12
+ gem 'guard-rubocop'
13
+ gem 'terminal-notifier-guard'
data/Guardfile ADDED
@@ -0,0 +1,81 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ group :red_green_refactor, halt_on_fail: true do
28
+ guard :rspec, cmd: "bin/rspec" do
29
+ require "guard/rspec/dsl"
30
+ dsl = Guard::RSpec::Dsl.new(self)
31
+
32
+ # Feel free to open issues for suggestions and improvements
33
+
34
+ # RSpec files
35
+ rspec = dsl.rspec
36
+ watch(rspec.spec_helper) { rspec.spec_dir }
37
+ watch(rspec.spec_support) { rspec.spec_dir }
38
+ watch(rspec.spec_files)
39
+
40
+ # Ruby files
41
+ ruby = dsl.ruby
42
+ dsl.watch_spec_files_for(ruby.lib_files)
43
+
44
+ # Rails files
45
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
46
+ dsl.watch_spec_files_for(rails.app_files)
47
+ dsl.watch_spec_files_for(rails.views)
48
+
49
+ watch(rails.controllers) do |m|
50
+ [
51
+ rspec.spec.("routing/#{m[1]}_routing"),
52
+ rspec.spec.("controllers/#{m[1]}_controller"),
53
+ rspec.spec.("acceptance/#{m[1]}")
54
+ ]
55
+ end
56
+
57
+ # Rails config changes
58
+ watch(rails.spec_helper) { rspec.spec_dir }
59
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
60
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
61
+
62
+ # Capybara features specs
63
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
64
+ watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
65
+
66
+ # Turnip features and steps
67
+ watch(%r{^spec/acceptance/(.+)\.feature$})
68
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
69
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
70
+ end
71
+ end
72
+
73
+ guard :rubocop do
74
+ watch(%r{.+\.rb$})
75
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
76
+ end
77
+
78
+ # guard :rails_best_practices, cmd: "bin/rails_best_practices" do
79
+ # watch(%r{^app/(.+)\.rb$})
80
+ # end
81
+ end
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # haasu-sutoon-data
2
+ This program generates a data file for [haasu-sutoon-chrome](https://github.com/tamano/haasu-sutoon-chrome)
3
+
4
+ ## Installation
5
+
6
+ $ gem install haasu-sutoon-data
7
+
8
+ ## Usage
9
+
10
+ $ haasu-sutoon-data generate filename
11
+
12
+ In case generating for [haasu-sutoon-chrome](https://github.com/tamano/haasu-sutoon-chrome), please output to `haasu-sutoon-chrome/data/cards.js`
13
+
14
+ ## Copyrights
15
+ - The contain data in the file generated by this program is provided by [Hearthstone JSON](https://hearthstonejson.com/).
16
+ - The file generated by this program that is Copyright © Blizzard Entertainment - All Rights Reserved.
17
+ - This program is not affiliated with Blizzard Entertainment in any way.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "haasu_sutoon_data"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ # require "irb"
14
+ # IRB.start
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,11 @@
1
+ machine:
2
+ timezone:
3
+ Asia/Tokyo
4
+
5
+ dependencies:
6
+ pre:
7
+ - gem install bundler --pre
8
+
9
+ test:
10
+ pre:
11
+ - bundle exec rubocop
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'haasu_sutoon_data'
4
+
5
+ HaasuSutoonData::CLI.start
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'haasu_sutoon_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'haasu-sutoon-data'
8
+ spec.version = HaasuSutoonData::VERSION
9
+ spec.authors = ['Yuya TAMANO']
10
+ spec.email = ['everfree.main@gmail.com']
11
+
12
+ spec.summary = 'tool to generate English-Japanese card dictionary from Hearthstonejson.com'
13
+ spec.description = 'See README.md for more information.'
14
+ spec.homepage = 'https://github.com/tamano/haasu-sutoon-data'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = 'exe'
25
+ spec.executables = ['haasu-sutoon-data']
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'thor'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.11'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'rubocop'
34
+ end
@@ -0,0 +1,5 @@
1
+ require 'thor'
2
+
3
+ require 'haasu_sutoon_data/cli'
4
+ require 'haasu_sutoon_data/file_generator'
5
+ require 'haasu_sutoon_data/version'
@@ -0,0 +1,14 @@
1
+ # command-line interface class
2
+ class HaasuSutoonData::CLI < Thor
3
+ desc \
4
+ 'generate {out_file}',
5
+ 'Access to Hearthstonejson.com and output English-Japanese cards list in JS Hash style named CardList.'
6
+ def generate(out_file)
7
+ if File.exist?(out_file)
8
+ puts "#{out_file} already exists"
9
+ exit 1
10
+ end
11
+
12
+ HaasuSutoonData.generate_file(out_file)
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ # get json file from Hearthstonejson.com and generate output_file
5
+ module HaasuSutoonData
6
+ def self.generate_file(file_path)
7
+ File.open(file_path, 'w') do |f|
8
+ f.write "console.log('card data version: #{HaasuSutoonData.file_id}');\n"
9
+ f.write "var CardList = [\n"
10
+ translate_cards_list.each do |card|
11
+ id = card['id']
12
+ en_name = card['en_name'].gsub("'", "\\\\'")
13
+ ja_name = card['ja_name'].gsub("'", "\\\\'")
14
+ f.write "{'id':'#{id}','en_name':'#{en_name}','ja_name':'#{ja_name}'},\n"
15
+ end
16
+ f.write "]\n"
17
+ end
18
+ end
19
+
20
+ def self.translate_cards_list
21
+ en_cards = JSON.parse(fetch_card_list('enUS'))
22
+ ja_cards = JSON.parse(fetch_card_list('jaJP'))
23
+
24
+ create_dictonary(en_cards, ja_cards)
25
+ end
26
+
27
+ def self.fetch_card_list(lang)
28
+ puts "Starting #{lang} card data download."
29
+
30
+ # jaJP => https://api.hearthstonejson.com/v1/latest/jaJP/cards.json
31
+ # enUS => https://api.hearthstonejson.com/v1/latest/enUS/cards.json
32
+ target_uri = URI("https://api.hearthstonejson.com/v1/latest/#{lang}/cards.json")
33
+
34
+ Net::HTTP.get(target_uri)
35
+ end
36
+
37
+ def self.create_dictonary(from_cards, to_cards)
38
+ puts 'Starting creating card dictonary.'
39
+
40
+ from_list = create_id_name_hash(from_cards)
41
+ to_list = create_id_name_hash(to_cards)
42
+
43
+ result = []
44
+
45
+ from_list.each do |id, en_name|
46
+ result << { 'id' => id, 'en_name' => en_name, 'ja_name' => to_list[id] }
47
+ end
48
+
49
+ result.sort do |a, b|
50
+ b['en_name'].size <=> a['en_name'].size
51
+ end
52
+ end
53
+
54
+ def self.create_id_name_hash(json)
55
+ Hash[*json.map { |c| [c['id'], c['name']] }.flatten]
56
+ end
57
+ end
@@ -0,0 +1,8 @@
1
+ # represent version
2
+ module HaasuSutoonData
3
+ VERSION = '0.1.0'
4
+
5
+ def self.file_id
6
+ "#{HaasuSutoonData::VERSION}/#{Time.now.strftime('%Y%m%d%H%M%S')}"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haasu-sutoon-data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuya TAMANO
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: See README.md for more information.
84
+ email:
85
+ - everfree.main@gmail.com
86
+ executables:
87
+ - haasu-sutoon-data
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".ruby-version"
95
+ - Gemfile
96
+ - Guardfile
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/rspec
101
+ - bin/setup
102
+ - circle.yml
103
+ - exe/haasu-sutoon-data
104
+ - haasu-sutoon-data.gemspec
105
+ - lib/haasu_sutoon_data.rb
106
+ - lib/haasu_sutoon_data/cli.rb
107
+ - lib/haasu_sutoon_data/file_generator.rb
108
+ - lib/haasu_sutoon_data/version.rb
109
+ homepage: https://github.com/tamano/haasu-sutoon-data
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.5
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: tool to generate English-Japanese card dictionary from Hearthstonejson.com
133
+ test_files: []