Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/espnscrape/ArrayConversions.rb
Overview
Array Extensions for Type Conversion
Instance Method Summary collapse
-
#boxscore(f_mat = nil) ⇒ NbaBoxscore
Get an NbaBoxscore.
-
#change_sym!(old_sym, new_sym) ⇒ Object
Replace old symbol with new symbol in Array.
-
#checkKeys(keys, k_id) ⇒ [Symbol]
Determine default field names.
-
#to_hashes(keys = []) ⇒ [Hash]
Create Hash Array.
-
#to_structs(keys = []) ⇒ [Struct]
Create Struct Array.
Instance Method Details
#boxscore(f_mat = nil) ⇒ NbaBoxscore
Get an NbaBoxscore
52 53 54 55 |
# File 'lib/espnscrape/ArrayConversions.rb', line 52 def boxscore(f_mat = nil) return nil unless size == S_GAME_P.size EspnScrape.boxscore(self[8], f_mat) end |
#change_sym!(old_sym, new_sym) ⇒ Object
Replace old symbol with new symbol in Array
45 46 47 |
# File 'lib/espnscrape/ArrayConversions.rb', line 45 def change_sym!(old_sym, new_sym) map! { |x| x.eql?(old_sym) ? new_sym : x } end |
#checkKeys(keys, k_id) ⇒ [Symbol]
Determine default field names
35 36 37 38 39 40 |
# File 'lib/espnscrape/ArrayConversions.rb', line 35 def checkKeys(keys, k_id) return keys unless keys.empty? [S_BOX_P, S_BOX_T, S_GAME_F, S_GAME_P, S_ROSTER, S_TEAM].each do |default| return default if default.size.eql?(k_id) end end |
#to_hashes(keys = []) ⇒ [Hash]
Create Hash Array
10 11 12 13 14 15 16 |
# File 'lib/espnscrape/ArrayConversions.rb', line 10 def to_hashes(keys = []) return [] if empty? two_d = first.is_a? Array # Check for 2D array keys = checkKeys(keys, two_d ? first.size : size) # Determine keys return [Hash[keys.map.with_index { |key, idx| [key, self[idx]] }]] unless two_d # 1D Array map { |ary| Hash[keys.map.with_index { |key, idx| [key, ary[idx]] }] } # 2D Array end |