class AhlScraper::Player

Public Class Methods

new(raw_data) click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 5
def initialize(raw_data)
  @raw_data = raw_data
end

Public Instance Methods

birthdate() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 37
def birthdate
  @birthdate ||= valid_birthdate? ? @raw_data.dig(:info, :birthDate) : nil
end
birthplace() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 29
def birthplace
  @birthplace ||= @raw_data.dig(:info, :birthPlace)&.strip
end
current_age() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 45
def current_age
  @current_age ||= valid_birthdate? ? BirthdateHelper.new(birthdate).current_age : nil
end
draft_year() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 41
def draft_year
  @draft_year ||= valid_birthdate? ? BirthdateHelper.new(birthdate).draft_year : nil
end
first_name() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 17
def first_name
  @first_name ||= @raw_data.dig(:info, :firstName)
end
handedness() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 25
def handedness
  @handedness ||= position == "G" ? @raw_data.dig(:info, :catches) : @raw_data.dig(:info, :shoots)
end
height() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 33
def height
  @height ||= @raw_data.dig(:info, :height_hyphenated)
end
id() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 9
def id
  @id ||= @raw_data.dig(:info, :playerId).to_i
end
jersey_number() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 49
def jersey_number
  @jersey_number ||= @raw_data.dig(:info, :jerseyNumber).to_i
end
last_name() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 21
def last_name
  @last_name ||= @raw_data.dig(:info, :lastName)
end
name() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 13
def name
  @name ||= "#{first_name} #{last_name}"
end
position() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 53
def position
  @position ||= @raw_data.dig(:info, :position)
end
weight() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 57
def weight
  @weight ||= @raw_data.dig(:info, :weight).to_i
end

Private Instance Methods

valid_birthdate?() click to toggle source
# File lib/ahl_scraper/resources/player.rb, line 63
def valid_birthdate?
  @valid_birthdate ||= !@raw_data.dig(:info, :birthDate).empty? && @raw_data.dig(:info, :birthDate) != "0000-00-00"
end