Class: NpbApi::PitchingStats
- Inherits:
-
Object
- Object
- NpbApi::PitchingStats
- Defined in:
- lib/npb_api/pitching_stats.rb
Instance Method Summary collapse
- #away ⇒ Object
- #home ⇒ Object
-
#initialize(date: '', id: '') ⇒ PitchingStats
constructor
A new instance of PitchingStats.
Constructor Details
#initialize(date: '', id: '') ⇒ PitchingStats
Returns a new instance of PitchingStats.
2 3 4 5 6 7 |
# File 'lib/npb_api/pitching_stats.rb', line 2 def initialize(date: '', id: '') @date = date @game_id = date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id @url = "http://baseball.yahoo.co.jp/npb/game/#{@game_id}/stats" @doc = TableExtraction.new(url: @url).doc end |
Instance Method Details
#away ⇒ Object
9 10 11 12 |
# File 'lib/npb_api/pitching_stats.rb', line 9 def away team = Nokogiri::HTML(open(@url)).css('.pitcher h4')[0].children[0].text stats(@doc[-2]).map { |s| s.merge({ team: team }) } end |
#home ⇒ Object
14 15 16 17 |
# File 'lib/npb_api/pitching_stats.rb', line 14 def home team = Nokogiri::HTML(open(@url)).css('.pitcher h4')[1].children[0].text stats(@doc[-1]).map { |s| s.merge({ team: team }) } end |