Class: AhlScraper::Player

Inherits:
Resource show all
Defined in:
lib/ahl_scraper/resources/player.rb

Instance Method Summary collapse

Methods inherited from Resource

#[], #each, #inspect, #keys, #to_json, #values

Constructor Details

#initialize(raw_data, opts = {}) ⇒ Player

Returns a new instance of Player.



5
6
7
# File 'lib/ahl_scraper/resources/player.rb', line 5

def initialize(raw_data, opts = {})
  super(raw_data, opts)
end

Instance Method Details

#birthdateObject



37
38
39
# File 'lib/ahl_scraper/resources/player.rb', line 37

def birthdate
  @birthdate ||= valid_birthdate? ? @raw_data.dig(:info, :birthDate) : nil
end

#birthplaceObject



29
30
31
# File 'lib/ahl_scraper/resources/player.rb', line 29

def birthplace
  @birthplace ||= @raw_data.dig(:info, :birthPlace)&.strip
end

#current_ageObject



45
46
47
# File 'lib/ahl_scraper/resources/player.rb', line 45

def current_age
  @current_age ||= valid_birthdate? ? BirthdateHelper.new(birthdate).current_age : nil
end

#draft_infoObject



61
62
63
# File 'lib/ahl_scraper/resources/player.rb', line 61

def draft_info
  @draft_info ||= Players::DraftInfo.new(draft_data)
end

#draft_yearObject



41
42
43
# File 'lib/ahl_scraper/resources/player.rb', line 41

def draft_year
  @draft_year ||= valid_birthdate? ? BirthdateHelper.new(birthdate).draft_year : nil
end

#first_nameObject



17
18
19
# File 'lib/ahl_scraper/resources/player.rb', line 17

def first_name
  @first_name ||= @raw_data.dig(:info, :firstName)
end

#handednessObject



25
26
27
# 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

#heightObject



33
34
35
# File 'lib/ahl_scraper/resources/player.rb', line 33

def height
  @height ||= @raw_data.dig(:info, :height_hyphenated)
end

#idObject



9
10
11
# File 'lib/ahl_scraper/resources/player.rb', line 9

def id
  @id ||= @raw_data.dig(:info, :playerId).to_i
end

#jersey_numberObject



49
50
51
# File 'lib/ahl_scraper/resources/player.rb', line 49

def jersey_number
  @jersey_number ||= @raw_data.dig(:info, :jerseyNumber).to_i
end

#last_nameObject



21
22
23
# File 'lib/ahl_scraper/resources/player.rb', line 21

def last_name
  @last_name ||= @raw_data.dig(:info, :lastName)
end

#nameObject



13
14
15
# File 'lib/ahl_scraper/resources/player.rb', line 13

def name
  @name ||= "#{first_name} #{last_name}"
end

#positionObject



53
54
55
# File 'lib/ahl_scraper/resources/player.rb', line 53

def position
  @position ||= @raw_data.dig(:info, :position)
end

#weightObject



57
58
59
# File 'lib/ahl_scraper/resources/player.rb', line 57

def weight
  @weight ||= @raw_data.dig(:info, :weight).to_i
end