infostrada 0.1.23 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTMzN2NiZWNjZTQ4M2I1ZTk5ZmEzOTgxZGUyMDRlODU3MTBhYmQ1NA==
4
+ MzE3NDBiNmMwMWIwNWI4ZTYzZDA0Y2UzMWI1OGZjYmVhMDMyMTM2NA==
5
5
  data.tar.gz: !binary |-
6
- MjU5ZTNhNDMzZjhjNzY1ODkzZTJiYzg4M2I1MGE0NmI0MmU0MjllYg==
6
+ NmZmZDE4MzNiNjIzMmUxZDkyNzFjNGY1MTQwYjNmOTQyMGVjN2U4YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTk4MGM0ZWY2YTZmNjQ0NzE0MjBiNjY0OTc2OWMxNTcyNWQ4MWJiNmMyMTNj
10
- MzJiMWRkMDY0ODEwN2FiNDlhNTU1ZDFlMjJlNjRiZGM1NGQ0YmY3OTFkYjE1
11
- ZTNhMTBiNjI3MDU4ZjcyMzNlYmU2MWZhZTMwZjkwZmM0NTNkZWQ=
9
+ NjM2NTY1MWU1YmJkMjY4MTIyYTYxYTUxMzk2Y2M3YmVkNjQ3N2ZlOTE3MjZh
10
+ YTY5MTNjOWQ5YjE1NGE3ODAxYTMzZjQzMjJhMDQxYmE1ZTc3MjdhNGRhMTk2
11
+ ZWI4YTk4ZTNjZjNhN2VmYzdmMDRiOWY2MDRkM2QzZGNhMWFjOTA=
12
12
  data.tar.gz: !binary |-
13
- YjlkMTgyY2Q3YTQwNjE2MTk5NWI2MjYyMjE4NDgxMzRjYmI3Yzc4YTc4MzA1
14
- YjEwNmZlY2E5YTJhNmQzNGU2MTRkYzhlNDc2ZGZlZGI3ZDk0ZWYzMTQyN2U5
15
- YzQ3NjkyMGE0MDc1Y2VmYTk4MWMyOWJkOWVlNTQ5YzU3MzRhYWI=
13
+ ZjQxNjgyZjQxMTJjZmM4NzdjMjQzYjExODgxZjFkODkyM2MxMjE0NzMzMGY2
14
+ NDEyM2UwNjkwNTc4YjQ5M2I5YjZlMWU3OWJlNmZmMTI0YmMyNzMxOTY2ZGIz
15
+ NDViZGUxOWM4MjQ1M2UyZmJiZjQxNDAyZTdkZDMzYzRkZjRlNmQ=
@@ -14,11 +14,21 @@ module Infostrada
14
14
  class Competition
15
15
  attr_accessor :id, :name, :set, :level, :nation
16
16
 
17
- def initialize(hash)
18
- @id = hash.delete('n_CompetitionID')
19
- @name = hash.delete('c_Competition')
17
+ def self.from_json(json = {})
18
+ self.new do |competition|
19
+ competition.id = json['id']
20
+ competition.name = json['name']
21
+ competition.nation = Nation.from_json(json['nation'], 'competition') if json['nation']
22
+ end
23
+ end
24
+
25
+ def initialize(hash = {}, &block)
26
+ @id = hash.delete('n_CompetitionID')
27
+ @name = hash.delete('c_Competition')
28
+ @nation = Nation.new(hash, 'competition') if hash.any?
20
29
 
21
- @nation = Nation.new(hash, 'competition')
30
+ block.call(self) if block_given?
31
+ self
22
32
  end
23
33
  end
24
- end
34
+ end
@@ -4,7 +4,7 @@ module Infostrada
4
4
  class Edition
5
5
  extend Forwardable
6
6
 
7
- attr_accessor :id, :competition, :season, :start_date, :end_date
7
+ attr_accessor :id, :competition, :season, :start_date, :end_date, :competition
8
8
 
9
9
  def_delegator :@competition, :name, :competition_name
10
10
  def_delegator :@competition, :id, :competition_id
@@ -13,14 +13,30 @@ module Infostrada
13
13
  editions = EditionRequest.get_list
14
14
  end
15
15
 
16
- def initialize(hash)
16
+ def self.from_json(json = {})
17
+ self.new do |edition|
18
+ edition.id = json['id']
19
+ edition.competition = json['competition']
20
+ edition.season = json['season']
21
+ edition.start_date = json['start_date']
22
+ edition.end_date = json['end_date']
23
+ edition.competition = Competition.from_json(json['competition'])
24
+ end
25
+ end
26
+
27
+ def initialize(hash = {}, &block)
17
28
  @id = hash.delete('n_EditionID')
18
29
  @season = hash.delete('c_Season')
19
- @start_date = Formatter.format_date(hash.delete('d_EditionStartDate'))
20
- @end_date = Formatter.format_date(hash.delete('d_EditionEndDate'))
30
+
31
+ if hash['d_EditionStartDate']
32
+ @start_date = Formatter.format_date(hash.delete('d_EditionStartDate'))
33
+ end
34
+
35
+ @end_date = Formatter.format_date(hash.delete('d_EditionEndDate')) if hash['d_EditionEndDate']
21
36
 
22
37
  @competition = Competition.new(hash)
23
38
 
39
+ block.call(self) if block_given?
24
40
  self
25
41
  end
26
42
 
@@ -99,51 +99,102 @@ module Infostrada
99
99
  list
100
100
  end
101
101
 
102
- def initialize(hash)
103
- @id = hash['n_MatchID']
104
- @date = Formatter.format_date(hash['d_DateUTC'])
105
- @rescheduled = hash['b_RescheduledToBeResumed']
106
- @round = hash['n_RoundNr']
107
- @time_unknown = hash['b_TimeUnknown']
108
- @date_unknown = hash['b_DateUnknown']
109
-
110
- @aggregate_winner_id = hash['n_WinnerOnAggregateTeamID']
102
+
103
+ # Useful method to get a Match object from a json serialized Match object.
104
+ def self.from_json(json = {})
105
+ self.new do |match|
106
+ match.id = json['id']
107
+ match.date = Time.parse(json['date']) if json['date']
108
+ match.rescheduled = json['rescheduled']
109
+ match.round = json['round']
110
+ match.time_unknown = json['time_unknown']
111
+ match.date_unknown = json['date_unknown']
112
+ match.aggregate_winner_id = json['aggregate_winner_id']
113
+
114
+ if json['current_period_started_at']
115
+ match.current_period_started_at = Time.parse(json['current_period_started_at'])
116
+ end
117
+
118
+ match.status_code = json['status_code']
119
+ match.status = json['status']
120
+ match.status_short = json['status_short']
121
+ match.leg = json['leg']
122
+ match.started_at = Time.parse(json['started_at']) if json['started_at']
123
+
124
+ match.stadium_id = json['stadium_id']
125
+ match.stadium_name = json['stadium_name']
126
+ match.spectators = json['spectators']
127
+ match.city = json['city']
128
+
129
+ match.live = json['live']
130
+ match.started = json['started']
131
+ match.finished = json['finished']
132
+ match.awarded = json['awarded']
133
+
134
+ match.live_score = json['live_score']
135
+ match.live_goals = json['live_goals']
136
+ match.live_lineup = json['live_lineup']
137
+
138
+ match.lineup_provisional = json['lineup_provisional']
139
+ match.lineup_official = json['lineup_official']
140
+
141
+ match.period = json['period']
142
+
143
+ match.referee = Referee.from_json(json['referee'])
144
+ match.phase = Phase.from_json(json['phase'])
145
+ match.home_team = Team.from_json(json['home_team'], 'home')
146
+ match.away_team = Team.from_json(json['away_team'], 'away')
147
+ match.goals = Goals.from_json(json['goals'])
148
+ match.edition = Edition.from_json(json['edition'])
149
+ end
150
+ end
151
+
152
+ def initialize(hash = {}, &block)
153
+ @id = hash['n_MatchID']
154
+ @date = Formatter.format_date(hash['d_DateUTC'])
155
+ @rescheduled = hash['b_RescheduledToBeResumed']
156
+ @round = hash['n_RoundNr']
157
+ @time_unknown = hash['b_TimeUnknown']
158
+ @date_unknown = hash['b_DateUnknown']
159
+
160
+ @aggregate_winner_id = hash['n_WinnerOnAggregateTeamID']
111
161
  @current_period_started_at = Formatter.format_date(hash['d_CurrentPeriodStartTime'])
112
- @status_code = hash['n_MatchStatusCode']
113
- @status = hash['c_MatchStatus']
114
- @status_short = hash['c_MatchStatusShort']
115
- @leg = hash['n_Leg']
116
- @started_at = Formatter.format_date(hash['d_MatchStartTime'])
162
+ @status_code = hash['n_MatchStatusCode']
163
+ @status = hash['c_MatchStatus']
164
+ @status_short = hash['c_MatchStatusShort']
165
+ @leg = hash['n_Leg']
166
+ @started_at = Formatter.format_date(hash['d_MatchStartTime'])
117
167
 
118
- @stadium_id = hash['n_StadiumGeoID']
119
- @stadium_name = hash['c_Stadium']
120
- @spectators = hash['n_Spectators']
121
- @city = hash['c_City']
168
+ @stadium_id = hash['n_StadiumGeoID']
169
+ @stadium_name = hash['c_Stadium']
170
+ @spectators = hash['n_Spectators']
171
+ @city = hash['c_City']
122
172
 
123
- @live = hash['b_Live']
124
- @started = hash['b_Started']
125
- @finished = hash['b_Finished']
126
- @awarded = hash['b_Awarded']
173
+ @live = hash['b_Live']
174
+ @started = hash['b_Started']
175
+ @finished = hash['b_Finished']
176
+ @awarded = hash['b_Awarded']
127
177
 
128
- @live_score = hash['b_DataEntryLiveScore']
129
- @live_goals = hash['b_DataEntryLiveGoal']
130
- @live_lineup = hash['b_DataEntryLiveLineup']
178
+ @live_score = hash['b_DataEntryLiveScore']
179
+ @live_goals = hash['b_DataEntryLiveGoal']
180
+ @live_lineup = hash['b_DataEntryLiveLineup']
131
181
 
132
- @lineup_provisional = hash['b_LineupProvisional']
133
- @lineup_official = hash['b_LineupOfficial']
182
+ @lineup_provisional = hash['b_LineupProvisional']
183
+ @lineup_official = hash['b_LineupOfficial']
134
184
 
135
- @period = hash['n_PeriodSort']
185
+ @period = hash['n_PeriodSort']
136
186
 
137
- @referee = Referee.new(hash)
138
- @phase = Phase.new(hash)
187
+ @referee = Referee.new(hash)
188
+ @phase = Phase.new(hash)
139
189
 
140
- @home_team = Team.new(hash, 'home')
141
- @away_team = Team.new(hash, 'away')
190
+ @home_team = Team.new(hash, 'home')
191
+ @away_team = Team.new(hash, 'away')
142
192
 
143
- @goals = Goals.new(hash)
193
+ @goals = Goals.new(hash)
144
194
 
145
- @edition = Edition.new(hash)
195
+ @edition = Edition.new(hash)
146
196
 
197
+ block.call(self) if block_given?
147
198
  self
148
199
  end
149
200
 
@@ -166,10 +217,25 @@ module Infostrada
166
217
 
167
218
  class Goals
168
219
  attr_accessor :home_goals, :away_goals, :home_goals_half_time, :away_goals_half_time,
169
- :home_goals_90_mins, :away_goals_90_mins, :home_goals_105_mins, :away_goals_150_mins,
220
+ :home_goals_90_mins, :away_goals_90_mins, :home_goals_105_mins, :away_goals_105_mins,
170
221
  :home_goals_shootout, :away_goals_shootout
171
222
 
172
- def initialize(hash)
223
+ def self.from_json(json = {})
224
+ self.new do |goals|
225
+ goals.home_goals = json['home_goals']
226
+ goals.away_goals = json['away_goals']
227
+ goals.home_goals_half_time = json['home_goals_half_time']
228
+ goals.away_goals_half_time = json['away_goals_half_time']
229
+ goals.home_goals_90_mins = json['home_goals_90_mins']
230
+ goals.away_goals_90_mins = json['away_goals_90_mins']
231
+ goals.home_goals_105_mins = json['home_goals_105_mins']
232
+ goals.away_goals_105_mins = json['away_goals_105_mins']
233
+ goals.home_goals_shootout = json['home_goals_shootout']
234
+ goals.away_goals_shootout = json['away_goald_shootout']
235
+ end
236
+ end
237
+
238
+ def initialize(hash = {}, &block)
173
239
  @home_goals = hash['n_HomeGoals']
174
240
  @away_goals = hash['n_AwayGoals']
175
241
  @home_goals_half_time = hash['n_HomeGoalsHalftime']
@@ -180,6 +246,9 @@ module Infostrada
180
246
  @away_goals_105_mins = hash['n_AwayGoals105mins']
181
247
  @home_goals_shootout = hash['n_HomeGoalsShootout']
182
248
  @away_goald_shootout = hash['n_AwayGoalsShootout']
249
+
250
+ block.call(self) if block_given?
251
+ self
183
252
  end
184
253
  end
185
254
  end
@@ -2,11 +2,23 @@ module Infostrada
2
2
  class Nation
3
3
  attr_accessor :id, :name, :short_name
4
4
 
5
- def initialize(hash, prefix)
5
+
6
+ def self.from_json(hash = {}, prefix)
7
+ self.new(prefix) do |nation|
8
+ nation.id = hash['id']
9
+ nation.name = hash['name']
10
+ nation.short_name = hash['short_name']
11
+ end
12
+ end
13
+
14
+ def initialize(hash = {}, prefix, &block)
6
15
  hash.each do |key, value|
7
16
  match = key.snake_case.match(/[cn]_#{prefix}_?(natio\w*)$/)
8
17
  self.send("#{$1}=", value) if match
9
18
  end
19
+
20
+ block.call(self) if block_given?
21
+ self
10
22
  end
11
23
 
12
24
  def natio_geo_id=(id)
@@ -15,8 +15,9 @@ module Infostrada
15
15
  URL = '/GetPhaseList'
16
16
 
17
17
  # Short name is only set outside GetPhaseList endpoint. For example on match list.
18
- attr_accessor :id, :name, :phase1_id, :phase1_name, :phase2_id, :phase2_name, :phase3_id, :level
19
- attr_accessor :phase3_name, :table, :current, :currents, :start_date, :end_date, :short_name
18
+ attr_accessor :id, :name, :phase1_id, :phase1_name, :phase2_id, :phase2_name, :phase3_id,
19
+ :level, :phase3_name, :table, :current, :currents, :start_date, :end_date,
20
+ :short_name, :has_table
20
21
 
21
22
  def self.where(options = {})
22
23
  edition_id = options.delete(:edition_id)
@@ -31,25 +32,46 @@ module Infostrada
31
32
  phases
32
33
  end
33
34
 
35
+ # Useful method to get a Phase object from a json serialized Phase object.
36
+ def self.from_json(json = {})
37
+ self.new do |phase|
38
+ phase.id = json['id']
39
+ phase.name = json['name']
40
+ phase.level = json['level']
41
+ phase.short_name = json['short_name']
42
+ phase.phase1_id = json['phase1_id']
43
+ phase.phase1_name = json['phase1_name']
44
+ phase.phase2_id = json['phase2_id']
45
+ phase.phase2_name = json['phase2_name']
46
+ phase.phase3_id = json['phase3_id']
47
+ phase.phase3_name = json['phase3_name']
48
+ phase.has_table = json['has_table']
49
+ phase.current = json['current']
50
+ phase.currents = json['currents']
51
+ phase.start_date = Date.parse(json['start_date']) if json['start_date']
52
+ phase.end_date = Date.parse(json['end_date']) if json['end_date']
53
+ end
54
+ end
55
+
34
56
  # Get the classification table for this phase.
35
57
  def table
36
58
  Table.where(phase_id: id)
37
59
  end
38
60
 
39
- def initialize(hash)
40
- @id = hash['n_PhaseID']
41
- @name = hash['c_Phase']
42
- @level = hash['n_PhaseLevel']
43
- @short_name = hash['c_PhaseShort']
44
- @phase1_id = hash['n_Phase1ID']
61
+ def initialize(hash = {}, &block)
62
+ @id = hash['n_PhaseID']
63
+ @name = hash['c_Phase']
64
+ @level = hash['n_PhaseLevel']
65
+ @short_name = hash['c_PhaseShort']
66
+ @phase1_id = hash['n_Phase1ID']
45
67
  @phase1_name = hash['c_Phase1']
46
- @phase2_id = hash['n_Phase2ID']
68
+ @phase2_id = hash['n_Phase2ID']
47
69
  @phase2_name = hash['c_Phase2']
48
- @phase3_id = hash['n_Phase3ID']
70
+ @phase3_id = hash['n_Phase3ID']
49
71
  @phase3_name = hash['c_Phase3']
50
- @has_table = hash['b_Table']
51
- @current = hash['b_Current']
52
- @currents = hash['b_Currents']
72
+ @has_table = hash['b_Table']
73
+ @current = hash['b_Current']
74
+ @currents = hash['b_Currents']
53
75
 
54
76
  # On GetPhaseList endpoint dates are just yyymmdd. Example: 20100629 (which translates to
55
77
  # 2010-06-29).
@@ -58,6 +80,7 @@ module Infostrada
58
80
  @end_date = Date.parse(hash['n_DateEnd'].to_s)
59
81
  end
60
82
 
83
+ block.call(self) if block_given?
61
84
  self
62
85
  end
63
86
 
@@ -2,12 +2,23 @@ module Infostrada
2
2
  class Referee
3
3
  attr_accessor :id, :name, :nation
4
4
 
5
- def initialize(hash)
5
+ def self.from_json(json = {})
6
+ self.new do |referee|
7
+ referee.id = json['id']
8
+ referee.name = json['name']
9
+ referee.nation = json['nation']
10
+ end
11
+ end
12
+
13
+ def initialize(hash = {}, &block)
6
14
  @id = hash.delete('n_RefereeID')
7
15
 
8
16
  @name = hash.delete('c_Referee')
9
17
 
10
18
  @nation = Nation.new(hash, 'referee')
19
+
20
+ block.call(self) if block_given?
21
+ self
11
22
  end
12
23
  end
13
24
  end
@@ -13,7 +13,17 @@ module Infostrada
13
13
  teams = TeamRequest.get_edition(edition_id.to_i)
14
14
  end
15
15
 
16
- def initialize(hash, prefix)
16
+ def self.from_json(json = {}, prefix)
17
+ self.new(prefix) do |team|
18
+ team.id = json['id']
19
+ team.name = json['name']
20
+ team.short_name = json['short_name']
21
+ team.nation = Nation.from_json(json['nation'], "#{prefix}_team") if json['nation']
22
+ team.edition_id = json['edition_id']
23
+ end
24
+ end
25
+
26
+ def initialize(hash = {}, prefix, &block)
17
27
  @edition_id = hash['edition_id']
18
28
 
19
29
  hash.each do |key, value|
@@ -26,8 +36,10 @@ module Infostrada
26
36
  self.send('team_short=', value)
27
37
  end
28
38
  end
29
-
30
39
  @nation = Nation.new(hash, "#{prefix}_team")
40
+
41
+ block.call(self) if block_given?
42
+ self
31
43
  end
32
44
 
33
45
  def team_id=(id)
@@ -1,3 +1,3 @@
1
1
  module Infostrada
2
- VERSION = '0.1.23'
2
+ VERSION = '0.1.24'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infostrada
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Otero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler