npb_api 0.1.2 → 0.2.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
  SHA1:
3
- metadata.gz: 0a2e67d3ccac6e050f0a33e2f89f8a5031e626c4
4
- data.tar.gz: a7fabb597936315bd3d3dce7bfef2346e076d4d8
3
+ metadata.gz: 153dbf022428d138453906f8fdba81a879fd0b7c
4
+ data.tar.gz: b709d2d14d30dc6f022ee352260fb2b32f7f44e6
5
5
  SHA512:
6
- metadata.gz: 60dc59e4b162d29ff9a8538998db0c0408654c832e18744da1f054f82309ecc65438684892f73c212213450e8887ee428c9528a12c1ac0b70467b58b38fa24ae
7
- data.tar.gz: e1156de4db32c3af3333bcf787491034b4d618f80a5553772163cb8234e27c569c1a6d7eaa8547cdc06edfa3b0ea6af076569bd2728f69b3d7bfb59e50b5ef22
6
+ metadata.gz: 00deef3e8de598b138f772685c88fef94bfe93f3293d25b4f304d8c3382e46c143f1f59f9cb2efebc1851b8d61334b351a1521b60dcd61727ba1ca543d4238a5
7
+ data.tar.gz: 5b0169a3478fa3132ccdbdb2fb30596fcf0656f5c703edc881051aaa7d8eef1d8f5bfe8a23422c58c602438944b5c229b04cbc5bb1fbdb6a7b088506aa8ee55d
@@ -43,7 +43,8 @@ class NpbApi::HittingStats
43
43
  stolen_bases: row.children[21].text.to_i,
44
44
  errors: row.children[23].text.to_i,
45
45
  home_runs: row.children[25].text.to_i,
46
- walks: walks(row),
46
+ bases_on_balls: bases_on_balls(row),
47
+ intentional_bases_on_balls: intentional_bases_on_balls(row),
47
48
  hit_by_pitch: hit_by_pitch(row),
48
49
  sacrifice_flies: sacrifice_flies(row),
49
50
  double_plays: double_plays(row),
@@ -74,10 +75,14 @@ class NpbApi::HittingStats
74
75
  $1
75
76
  end
76
77
 
77
- def walks(row)
78
+ def bases_on_balls(row)
78
79
  details(row).values.count('四球')
79
80
  end
80
81
 
82
+ def intentional_bases_on_balls(row)
83
+ details(row).values.count('敬遠')
84
+ end
85
+
81
86
  def hit_by_pitch(row)
82
87
  details(row).values.count('死球')
83
88
  end
@@ -21,7 +21,6 @@ class NpbApi::PitchingStats
21
21
  def stats(doc)
22
22
  rows = doc.css('tr')
23
23
  rows.shift
24
- rows
25
24
  order = 0
26
25
  rows.each_with_object([]) do |row, arr|
27
26
  order += 1
@@ -0,0 +1,101 @@
1
+ class NpbApi::Player
2
+ def initialize(id: '')
3
+ @id = id
4
+ @doc = Nokogiri::HTML(open("http://baseball.yahoo.co.jp/npb/player/#{id}/")).css('#profile')
5
+ end
6
+
7
+ def info
8
+ {
9
+ id: @id,
10
+ name: @doc.css('.NpbTeamTop').children.children[0].text,
11
+ kana: kana,
12
+ number: @doc.css('.NpbTeamTop').children.children.children[1].text,
13
+ position: @doc.css('.NpbTeamTop').children.children.children[2].text,
14
+ birthday: birthday,
15
+ age: age,
16
+ birthplace: @doc.css('tr')[0].children.children[-1].text,
17
+ height: height,
18
+ weight: weight,
19
+ blood_type: blood_type,
20
+ throw: _throw,
21
+ bat: bat,
22
+ draft_year: draft_year,
23
+ draft_rank: draft_rank,
24
+ total_years: total_years,
25
+ carrier: @doc.css('tr')[3].children.children[-1].text,
26
+ title: title
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def kana
33
+ @doc.css('.NpbTeamTop').children.children.children[0].text =~ /\A((.+))\z/
34
+ $1
35
+ end
36
+
37
+ def birthday
38
+ @doc.css('tr')[0].children.children[2].text =~ /\A(\d{4})年(\d{1,2})月(\d{1,2})日(\d{2}歳)\z/
39
+ Date.new($1.to_i, $2.to_i, $3.to_i)
40
+ end
41
+
42
+ def age
43
+ @doc.css('tr')[0].children.children[2].text =~ /\A\d{4}年\d{1,2}月\d{1,2}日((\d{2})歳)\z/
44
+ $1.to_i
45
+ end
46
+
47
+ def height
48
+ @doc.css('tr')[1].children.children[1].text =~ /\A(\d{3})cm\/\d{2,3}kg(.+)\z/
49
+ $1.to_i
50
+ end
51
+
52
+ def weight
53
+ @doc.css('tr')[1].children.children[1].text =~ /\A\d{3}cm\/(\d{2,3})kg(.+)\z/
54
+ $1.to_i
55
+ end
56
+
57
+ def blood_type
58
+ @doc.css('tr')[1].children.children[1].text =~ /\A\d{3}cm\/\d{2,3}kg((.+))\z/
59
+ $1
60
+ end
61
+
62
+ # NOTE: 予約語と重複するためアンスコをつけている
63
+ def _throw
64
+ @doc.css('tr')[1].children.children[-1].text =~ /\A(.)投げ.打ち\z/
65
+ $1
66
+ end
67
+
68
+ def bat
69
+ @doc.css('tr')[1].children.children[-1].text =~ /\A.投げ(.)打ち\z/
70
+ $1
71
+ end
72
+
73
+ def draft_year
74
+ if @doc.css('tr')[2].children.children[1].text =~ /\A(\d{4})年(.+)\z/
75
+ $1.to_i
76
+ else
77
+ nil
78
+ end
79
+ end
80
+
81
+ def draft_rank
82
+ if @doc.css('tr')[2].children.children[1].text =~ /\A\d{4}年((.+))\z/
83
+ $1
84
+ else
85
+ nil
86
+ end
87
+ end
88
+
89
+ def total_years
90
+ @doc.css('tr')[2].children.children[-1].text =~ /\A(\d+)年\z/
91
+ $1.to_i
92
+ end
93
+
94
+ def title
95
+ if @doc.css('tr')[4].children.children[-1].text == '-'
96
+ nil
97
+ else
98
+ @doc.css('tr')[4].children.children[-1].text
99
+ end
100
+ end
101
+ end
data/lib/npb_api.rb CHANGED
@@ -6,3 +6,4 @@ end
6
6
  require 'npb_api/game'
7
7
  require 'npb_api/hitting_stats'
8
8
  require 'npb_api/pitching_stats'
9
+ require 'npb_api/player'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: npb_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ohtsuka Takahiro
@@ -62,6 +62,7 @@ files:
62
62
  - lib/npb_api/game.rb
63
63
  - lib/npb_api/hitting_stats.rb
64
64
  - lib/npb_api/pitching_stats.rb
65
+ - lib/npb_api/player.rb
65
66
  homepage: https://github.com/to0526/npb_api
66
67
  licenses:
67
68
  - MIT