Sha256: a702a0ee61069c4dbf7413faa06a590e02d1f7c2e700f580a8091706a68d9aa7
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true module AhlScraper class Player < Resource def initialize(raw_data) @raw_data = raw_data end def id @id ||= @raw_data.dig(:info, :playerId).to_i end def name @name ||= "#{first_name} #{last_name}" end def first_name @first_name ||= @raw_data.dig(:info, :firstName) end def last_name @last_name ||= @raw_data.dig(:info, :lastName) end def handedness @handedness ||= position == "G" ? @raw_data.dig(:info, :catches) : @raw_data.dig(:info, :shoots) end def birthplace @birthplace ||= @raw_data.dig(:info, :birthPlace)&.strip end def height @height ||= @raw_data.dig(:info, :height_hyphenated) end def birthdate @birthdate ||= valid_birthdate? ? @raw_data.dig(:info, :birthDate) : nil end def draft_year @draft_year ||= valid_birthdate? ? BirthdateHelper.new(birthdate).draft_year : nil end def current_age @current_age ||= valid_birthdate? ? BirthdateHelper.new(birthdate).current_age : nil end def jersey_number @jersey_number ||= @raw_data.dig(:info, :jerseyNumber).to_i end def position @position ||= @raw_data.dig(:info, :position) end def weight @weight ||= @raw_data.dig(:info, :weight).to_i end private def valid_birthdate? @valid_birthdate ||= !@raw_data.dig(:info, :birthDate).empty? && @raw_data.dig(:info, :birthDate) != "0000-00-00" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ahl_scraper-0.2.0 | lib/ahl_scraper/resources/player.rb |