Class: Sportradar::Api::Data
- Inherits:
-
Object
- Object
- Sportradar::Api::Data
show all
- Defined in:
- lib/sportradar/api/data.rb
Direct Known Subclasses
Baseball::Error, Baseball::Event, Baseball::Event::AtBat, Baseball::Event::Lineup, Baseball::Event::WarmingUp, Baseball::Fielder, Baseball::Game, Baseball::HalfInning, Baseball::Inning, Baseball::Lineup, Baseball::Mlb, Baseball::Mlb::Division, Baseball::Mlb::League, Baseball::Outcome, Baseball::Pitch, Baseball::Player, Baseball::Record, Baseball::Runner, Baseball::Scoring, Baseball::Team, Baseball::Venue, Basketball::Broadcast, Basketball::Game, Basketball::Injury, Basketball::Nba, Basketball::Nba::Conference, Basketball::Nba::Division, Basketball::Nba::Player, Basketball::Nba::Quarter, Basketball::Nba::Schedule, Basketball::Ncaamb, Basketball::Ncaamb::Bracket, Basketball::Ncaamb::Conference, Basketball::Ncaamb::Division, Basketball::Ncaamb::Half, Basketball::Ncaamb::Hierarchy, Basketball::Ncaamb::Player, Basketball::Ncaamb::Round, Basketball::Ncaamb::Schedule, Basketball::Ncaamb::Tournament, Basketball::Play, Basketball::Play::Base, Basketball::Record, Basketball::Scoring, Basketball::Season, Basketball::Team, Basketball::Venue, Broadcast, Content::Article, Content::ArticleList, Content::Reference, Football::BlockStatistics, Football::ConversionStatistics, Football::Drive, Football::Event, Football::Game, Football::GameStats, Football::MiscStatistics, Football::Ncaafb, Football::Ncaafb::Conference, Football::Ncaafb::Division, Football::Ncaafb::Subdivision, Football::Nfl, Football::Nfl::Conference, Football::Nfl::DepthChart, Football::Nfl::Division, Football::Nfl::LeagueDepthChart, Football::Nfl::TeamDepthChart, Football::Play, Football::PlayDefenseStatistics, Football::PlayDownConversionStatistics, Football::PlayExtraPointStatistics, Football::PlayFieldGoalStatistics, Football::PlayFirstDownStatistics, Football::PlayFumbleStatistics, Football::PlayKickStatistics, Football::PlayPassingStatistics, Football::PlayPenaltyStatistics, Football::PlayPuntStatistics, Football::PlayReceiveStatistics, Football::PlayReturnStatistics, Football::PlayRushStatistics, Football::PlayStatistics, Football::Player, Football::Quarter, Football::Record, Football::Scoring, Football::Situation, Football::StatPack, Football::Team, Football::Venue, Football::Week, Images::Asset, Images::AssetList, Images::Link, Images::Ref, Images::Tag, Mma::Competition, Mma::Event, Mma::Fight, Mma::Fighter, Mma::Judge, Mma::League, Mma::Referee, Mma::Result, Mma::Roster, Mma::Schedule, Mma::Score, Mma::Season, Mma::Venue, Odds::Base, Odds::Book, Odds::BookMarket, Odds::Competition, Odds::Market, Odds::Outcome, Odds::Player, Odds::PlayerProp, Odds::Sport, Odds::SportEvent, Soccer::Competition, Soccer::Event, Soccer::Fact, Soccer::Group, Soccer::Lineup, Soccer::Match, Soccer::Player, Soccer::Scoring, Soccer::Season, Soccer::Standing, Soccer::Team, Soccer::TeamGroup, Soccer::Tournament, Soccer::Venue
Instance Method Summary
collapse
Instance Method Details
#all_attributes ⇒ Object
10
11
12
|
# File 'lib/sportradar/api/data.rb', line 10
def all_attributes
self.instance_variables.map{|attribute| attribute.to_s.gsub('@', '').to_sym }
end
|
#attributes ⇒ Object
Attributes that have a value
6
7
8
|
# File 'lib/sportradar/api/data.rb', line 6
def attributes
all_attributes.select {|x| !self.send(x).nil? }
end
|
#create_data(existing = {}, data, klass: nil, identifier: 'id', **opts) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/sportradar/api/data.rb', line 51
def create_data(existing = {}, data, klass: nil, identifier: 'id', **opts)
existing ||= {} case data
when [], {}
existing
when Array
data.each do |hash|
current = existing[hash[identifier]]
if current
current.update(hash, **opts)
else
current = klass.new(hash, **opts)
existing[current.id] = current
end
existing[current.id]
end
when Hash
existing[data[identifier]] ||= klass.new(data, **opts)
existing[data[identifier]].update(data, **opts)
else
end
existing
end
|
#parse_into_array(selector:, klass:) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/sportradar/api/data.rb', line 14
def parse_into_array(selector: , klass: )
if selector.is_a?(Array)
selector.map {|x| klass.new x }
elsif selector.is_a?(Hash)
[ klass.new(selector) ]
end
end
|
#parse_into_array_with_options(selector:, klass:, **opts) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/sportradar/api/data.rb', line 21
def parse_into_array_with_options(selector: , klass: , **opts)
if selector.is_a?(Array)
selector.map {|x| klass.new(x, **opts) }
elsif selector.is_a?(Hash)
[ klass.new(selector, **opts) ]
else
[]
end
end
|
#parse_out_hashes(data_element) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/sportradar/api/data.rb', line 76
def parse_out_hashes(data_element)
if data_element && data_element.is_a?(Array)
data_element.find {|elem| elem.is_a?(Hash) }
else
data_element
end
end
|
#structure_links(links_arr) ⇒ Object
31
32
33
|
# File 'lib/sportradar/api/data.rb', line 31
def structure_links(links_arr)
links_arr.map { |hash| [hash['rel'], hash['href'].gsub('.xml', '')] }.to_h
end
|
#update_data(existing, data) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/sportradar/api/data.rb', line 37
def update_data(existing, data)
case data
when Array
data.each { |hash| existing[hash['id']].update(hash) }
when Hash
existing[data['id']].update(data)
else
end
existing
end
|