class Npbs::Player

Attributes

birthday[R]
college[R]
company[R]
first_name[R]
first_name_kana[R]
height[R]
high_school[R]
last_name[R]
last_name_kana[R]
name[R]
number[R]
path[R]
weight[R]

Public Class Methods

new(name, path) click to toggle source
Calls superclass method Npbs::NPB::new
# File lib/npbs.rb, line 34
def initialize(name, path)
  super()
  @name = name
  @path = path
end

Public Instance Methods

fetch() click to toggle source
# File lib/npbs.rb, line 39
def fetch
  doc = fetch_doc
  name = @name.split(' ')
  @first_name = name[0]
  @last_name = name[1]
  if @last_name.nil? && doc.css('.registerPlayer h1').inner_text.match('(')
    name = doc.css('.registerPlayer h1').inner_text.match('(.*)').to_s.split(' ')
    if name[1].nil?
      name = doc.css('.registerPlayer h1').inner_text.match('(.*)').to_s.split('・')          
    end
    @first_name = name[0].gsub('(','')
    @last_name = name[1].gsub(')','')
  end

  @number = doc.css('#registerdivtitle .registerNo').inner_text

  doc.css('#registerdivCareer').each do |prof|
    name_kana = prof.css("tr:first-child td").inner_text.split('・')
    @first_name_kana = name_kana[0]
    @last_name_kana = name_kana[1]
    # 外人対応
    if prof.css("tr:first-child td").inner_text =~ /[A-Z]/
      name_data = prof.css("tr:first-child td").inner_text.split('(')
      real_name = name_data[0].split('・')
      @first_name = real_name[0]
      @last_name = real_name[1]
      kana = name_data[1].nil? ? name_data[0].split(/\s/) : name_data[1].split(/\s/)
      @first_name_kana = kana[0].gsub(/(/,'')
      @last_name_kana = kana[1..-1].join(' ').gsub(/)/,'')
      if @first_name.nil? || @last_name.nil?
        @first_name = @first_name_kana
        @last_name = @last_name_kana
      end
    end
    @first_name = @first_name.gsub(/(\s| )/,' ').gsub(/^.*(/,'')
    @last_name = @last_name.gsub(/(\s| )/,' ').gsub(/)/,'')
    @first_name_kana = @first_name_kana.gsub(/(\s| )/,' ').gsub(/^.*(/,'')
    @last_name_kana = @last_name_kana.gsub(/(\s| )/,' ').gsub(/)/,'')
    data = prof.css('tr:nth-child(2) td').inner_text.split(' ')
    data.delete('')
    @birthday = Date.strptime(data[0],'%Y年%m月%d日生')
    @height = data[1].match(/[0-9]{3,}/).to_s
    @weight = data[2].match(/[0-9]{2,3}/).to_s
    history = prof.css('tr:nth-child(3) td').inner_text.split(' - ')
    history.delete('')
    @high_school =  history[0]
    if history.length == 2 && /大$/ === history[1] then
      @college = history[1]
    elsif history.length == 2 then
      @company = history[1]
    end
  end
end