d1lcs 0.1.2

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: 63c81e9c0b02fff50392b83583adad3d7d3ac547
4
+ data.tar.gz: 1fb873068482aa49f129554a34994a9dacadf308
5
+ SHA512:
6
+ metadata.gz: dab40162096370293d23137c7fea15982280c39f4add1d56845070d8d7d6bc15d7c5b7891014b61e9c61ffdfa40bbcdddf9403a0ad17ac6123e23a4a75178f04
7
+ data.tar.gz: 0c288279b5f558375d2cadabeac5a0289b0acbe8ade5d0055e2c1d60719efbcf3be082116542305618ef23829346999b3af7a55d417e74066c5445bc30c3cbbd
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/.travis.yml ADDED
@@ -0,0 +1,27 @@
1
+ language: ruby
2
+ rvm:
3
+ - '1.9.3'
4
+ - '2.0.0'
5
+ - '2.1.7'
6
+ - '2.2.3'
7
+ before_install: gem install bundler -v 1.10.6
8
+ bundler_args: --path vendor/bundle
9
+ cache:
10
+ directories:
11
+ - vendor/bundle
12
+ script:
13
+ - 'bundle exec bin/d1lcs --help'
14
+ - 'bundle exec bin/d1lcs 1'
15
+ - 'bundle exec bin/d1lcs title 1'
16
+ - 'bundle exec bin/d1lcs 1 2 title'
17
+ notifications:
18
+ irc:
19
+ use_notice: true
20
+ channels:
21
+ - 'irc.trpg.net#koi-chan'
22
+ on_success: always
23
+ on_failure: always
24
+ template:
25
+ - '%{repository_slug} #%{build_number} %{branch} - %{commit} -> %{result}'
26
+ - '変更履歴: %{compare_url}'
27
+ - 'ステータス: %{build_url}'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in d1lcs.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # D1lcs
2
+
3
+ でたとこサーガ用1行のキャラクターシート生成ライブラリ
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'd1lcs'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install d1lcs
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec d1lcs` to use the gem in this directory, ignoring other installed copies of this gem.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/d1lcs.
34
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ #require "rspec/core/rake_task"
3
+
4
+ #RSpec::Core::RakeTask.new(:spec)
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ #task :default => :spec
data/bin/d1lcs ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ require "bundler/setup"
5
+ require "d1lcs"
6
+
7
+ def output_help
8
+ print <<__EOT__
9
+ でたとこサーガ用1行のキャラクターシート生成ツール
10
+ 出力したいキャラクターシートIDをオプションで指定してください。
11
+ 半角空白で区切ると複数のキャラクターについて出力できます。
12
+ title という文字をオプションの中に含めると、タイトル行を先頭に出力します。
13
+
14
+ キャラクターIDの調べ方
15
+ 『でたとこサーガ』公式サイトの「キャラクターシート登録所」のキャラクターページのURLをご覧ください。
16
+ 最後に書かれた数字が、そのキャラクターのIDです。
17
+ 「王道勇者」(http://detatoko-saga.com/character/1) の場合、IDは 1 になります。
18
+
19
+ 例:
20
+ $ d1lcs title 1
21
+ 名前 |Lv|体力 気力 旗|クラス |スキル   |意感交肉技知|ID |プレイヤー
22
+ 王道勇者 |1|11/11 10/10 0|勇者戦士|聖希折鉄強必|11 4  | 1|でたとこサーガ
23
+
24
+ $ d1lcs 1 2
25
+ 王道勇者 |1|11/11 10/10 0|勇者戦士|聖希折鉄強必|11 4  | 1|でたとこサーガ
26
+ 暗黒魔王 |1|10/10 11/11 0|魔王暗黒|無圧極ド暗愉|311  1| 2|でたとこサーガ
27
+
28
+ __EOT__
29
+ end
30
+
31
+ outputs = [nil]
32
+ errors = []
33
+
34
+ ARGV.each { |arg|
35
+ case arg
36
+ when /-h|--help/
37
+ output_help
38
+ exit
39
+ when 'title'
40
+ outputs[0] = D1lcs.title_line
41
+ else
42
+ cs = D1lcs::Element.new(arg)
43
+ if(cs.error != nil)
44
+ errors << cs.error
45
+ next
46
+ end
47
+ outputs << cs.chara_sheet_line
48
+ end
49
+ }
50
+
51
+ puts outputs.compact
52
+ puts errors
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/d1lcs.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'd1lcs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "d1lcs"
8
+ spec.version = D1lcs::VERSION
9
+ spec.licenses = ['MIT']
10
+ spec.authors = ["koi-chan"]
11
+ spec.email = ["koi-chan@mail.kazagakure.net"]
12
+
13
+ spec.summary = %q{でたとこサーガ用1行キャラクターシート出力}
14
+ spec.description = %q{TRPG『でたとこサーガ』用の1行キャラクターシートを生成します。}
15
+ spec.homepage = "https://github.com/koi-chan/d1lcs-gem"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,164 @@
1
+ # coding: UTF-8
2
+ require 'd1lcs/string'
3
+
4
+ require 'json'
5
+ require 'open-uri'
6
+ require 'logger'
7
+
8
+ module D1lcs
9
+ class Element
10
+ # 1キャラシ(1行)を作成する各要素を用意するためのクラス
11
+
12
+ # オンラインキャラクターシートのJSON出力用URL
13
+ CHARA_SHEET_URL = 'http://detatoko-saga.com/character/%d.json'
14
+
15
+ # エラーが発生した時
16
+ attr_reader :error
17
+
18
+ # JSON でデータを取り込む
19
+ # @param id [Fixnum] オンラインキャラシの登録ID
20
+ # @return [String] 完成した1行キャラシ
21
+ # ToDo: エラー処理を書く
22
+ def initialize(request)
23
+ @logger = Logger.new(STDERR)
24
+ @logger.progname = 'Detatoko1LineCharaSheet'
25
+
26
+ unless @request = check_id(request)
27
+ @error = "Error: キャラクターシートID '#{request}' は無効です"
28
+ return
29
+ end
30
+ if (@chara_sheet = json_parse) == nil
31
+ @error = "Error: キャラクターシートID '#{request}' を読み込めませんでした"
32
+ return
33
+ end
34
+
35
+ @pcname = pcname
36
+ @level = level
37
+ @hpmp = hpmp
38
+ @classes = classes
39
+ @skills = skills
40
+ @timing, @janre = timing_janre
41
+ @charaID = charaID
42
+ @plname = plname
43
+ end
44
+
45
+ # 1行キャラクターシートを出力する
46
+ # @return [String]
47
+ def chara_sheet_line
48
+ [@pcname, @level, @hpmp, @classes, @skills, @janre, @charaID, @plname].join('|')
49
+ end
50
+ alias :print :chara_sheet_line
51
+ alias :to_s :chara_sheet_line
52
+
53
+ private
54
+
55
+ # PC の名前
56
+ # @return [String]
57
+ def pcname
58
+ @chara_sheet['name'].dispformat(NAME_WIDTH)
59
+ end
60
+
61
+ # PC のレベル
62
+ # @return [String]
63
+ def level
64
+ unify_dispsize2(@chara_sheet['level'].to_s)
65
+ end
66
+
67
+ # 体力・気力・フラグ
68
+ # @return [String]
69
+ def hpmp
70
+ hpmp = ''
71
+ %w(h m).each { |type|
72
+ hpmp << (@chara_sheet["#{type}p"]['total'].to_s * 2).insert(2, '/')
73
+ }
74
+ hpmp.insert(-6, ' ') << ' 0'
75
+ end
76
+
77
+ # クラス
78
+ # @return [String]
79
+ def classes
80
+ @chara_sheet['class'].map { |array| classID_short(array['id']) }.join
81
+ end
82
+
83
+ # スキル
84
+ # @return [String]
85
+ def skills
86
+ @chara_sheet['skill'].map { |array| array['name'].chars.first }.join
87
+ end
88
+
89
+ # スキルタイミング・ジャンル
90
+ # @return [Array<String>] [timing, string] の順番
91
+ def timing_janre
92
+ timing = [0, 2, 1, 0]
93
+ janre = Array.new(6, 0)
94
+ @chara_sheet['skill'].each { |skill|
95
+ timing[skill['timing'].to_i - 1] += 1
96
+ janre[skill['janre'].to_i - 1] += 1
97
+ }
98
+ [timing, janre].map { |array|
99
+ array.map { |value|
100
+ unify_dispsize2(value.to_s).tr('0', ' ')
101
+ }.join
102
+ }
103
+ end
104
+
105
+ # キャラクターID
106
+ # @return [String]
107
+ def charaID
108
+ "#{'% 4d' % @chara_sheet['id']}"
109
+ end
110
+
111
+ # プレイヤー名
112
+ # @return [String]
113
+ def plname
114
+ @chara_sheet['player_name']
115
+ end
116
+
117
+ # リクエストされたキャラクターIDが正しいか確認する
118
+ # @param [String] request
119
+ # @return [Fixnum/false]
120
+ def check_id(request)
121
+ id = request.to_i
122
+ case id
123
+ when 0
124
+ false
125
+ else
126
+ id
127
+ end
128
+ end
129
+
130
+ # 公式キャラシから JSON をダウンロードし、Hash に変換する
131
+ # @return [Hash]
132
+ def json_parse
133
+ begin
134
+ JSON.parse(open(URI.parse(CHARA_SHEET_URL % @request)).read)
135
+ rescue => e
136
+ @logger.error { ["requestID:#{@request}", e.class, e].join(' : ') }
137
+ nil
138
+ end
139
+ end
140
+
141
+ # 半角2文字幅で表示をそろえるため数字の全角・半角を調整する
142
+ # @param [String] num 整数(1桁もしくは2桁)
143
+ # @result [String] 1桁なら全角に、2桁なら半角の整数
144
+ def unify_dispsize2(num)
145
+ case num.size
146
+ when 1
147
+ num.half_to_full
148
+ when 2
149
+ num.full_to_half
150
+ end
151
+ end
152
+
153
+ # クラスIDから全角2文字の短縮形に変換する
154
+ # @param [Fixnum] class_id JSONから読み込むことを考慮し文字列型
155
+ # @return [String]
156
+ def classID_short(class_id)
157
+ class_ids = ['勇者', '魔王', '姫様', 'ドラ', '戦士', '魔使',
158
+ '神聖', '暗黒', 'マス', 'モン', '謎 ', 'ザコ',
159
+ 'メカ', '商人', '占師' # フロンティア
160
+ ]
161
+ class_ids[class_id.to_i - 1]
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,64 @@
1
+ # coding: UTF-8
2
+
3
+ class String
4
+ # 数字を全角に変換する
5
+ def half_to_full
6
+ self.tr('0-9', '0-9')
7
+ end
8
+
9
+ # 数字を半角に変換する
10
+ def full_to_half
11
+ self.tr('0-9', '0-9')
12
+ end
13
+
14
+ # 文字列を表示するために使うサイズを返す
15
+ def dispsize
16
+ charsize = 0
17
+
18
+ self.each_char do |char|
19
+ if char.bytesize > 1
20
+ charsize += 2
21
+ else
22
+ charsize += 1
23
+ end
24
+ end
25
+
26
+ charsize
27
+ end
28
+
29
+ # 表示サイズに文字列を切り詰める
30
+ # @param long [Fixnum] 生成文字列の長さ
31
+ # @param dot [Boolean] 末尾に … を付加するか
32
+ # @return [String]
33
+ def dispsize_cut(long, dot = false)
34
+ return self if self.dispsize <= long
35
+
36
+ result = ''
37
+ chars = self.chars
38
+ nowlong = dot ? 2 : 0
39
+
40
+ chars.each { |char|
41
+ if (nowlong += char.dispsize) <= long
42
+ result << char
43
+ end
44
+ }
45
+
46
+ result << '…' if dot
47
+ result << ' ' unless result.dispsize == long
48
+ result
49
+ end
50
+
51
+ # 指定した長さに丸めたり末尾に空白を挿入したりする
52
+ # @return [String]
53
+ def dispformat(target)
54
+ long = self.dispsize
55
+ case long
56
+ when 1..target - 1
57
+ self + ' ' * (target - long)
58
+ when target
59
+ self
60
+ else
61
+ self.dispsize_cut(target, true)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module D1lcs
2
+ VERSION = "0.1.2"
3
+ end
data/lib/d1lcs.rb ADDED
@@ -0,0 +1,23 @@
1
+ # coding: UTF-8
2
+ require 'd1lcs/version'
3
+ require 'd1lcs/string'
4
+ require 'd1lcs/element'
5
+
6
+ module D1lcs
7
+ # 名前項目の文字数(半角換算の幅)をいくつに設定するか。
8
+ NAME_WIDTH = 12
9
+
10
+ # 1行キャラシのタイトル行を出力する
11
+ # @return [String]
12
+ def self.title_line
13
+ [ '名前'.dispformat(NAME_WIDTH),
14
+ 'Lv',
15
+ '体力 気力 旗',
16
+ 'クラス ',
17
+ 'スキル   ',
18
+ '意感交肉技知',
19
+ 'ID ',
20
+ 'プレイヤー'
21
+ ].join('|')
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: d1lcs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - koi-chan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: TRPG『でたとこサーガ』用の1行キャラクターシートを生成します。
70
+ email:
71
+ - koi-chan@mail.kazagakure.net
72
+ executables:
73
+ - d1lcs
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - bin/d1lcs
85
+ - bin/setup
86
+ - d1lcs.gemspec
87
+ - lib/d1lcs.rb
88
+ - lib/d1lcs/element.rb
89
+ - lib/d1lcs/string.rb
90
+ - lib/d1lcs/version.rb
91
+ homepage: https://github.com/koi-chan/d1lcs-gem
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.8
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: でたとこサーガ用1行キャラクターシート出力
115
+ test_files: []
116
+ has_rdoc: