mlb_rb 0.0.3 → 0.0.4
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/mlb_rb/errors.rb +5 -0
- data/lib/mlb_rb/games.rb +51 -0
- data/lib/mlb_rb/version.rb +1 -1
- data/lib/mlb_rb.rb +1 -48
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9425c40e4217cb73a792654e606c3bf7f2433f666a4ce3d07a0f30a10429f073
|
|
4
|
+
data.tar.gz: 5a9442a40f8e4a6b5b01545f31253159fce41a937b9922918e0fdfbf27020e12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb2cb494634507cf491832e7b6a2133e933c25867f034388c7b4617eca2fc1999a297109b5dc13a8b277f8537c59b0051041ed0b9f3a244d806e9d614ae46f9e
|
|
7
|
+
data.tar.gz: fff2f9342f928a7df737e8b3b21d6c25ab5cf4a8a19d8b2d78e247e0ea9f8ffe309e42ddb3a23fbc07f16041c68e250b1c36163a5eb01c85e0bfc244b1c97526
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -25,8 +25,8 @@ Or install it yourself as:
|
|
|
25
25
|
There are currently only two methods available:
|
|
26
26
|
|
|
27
27
|
```ruby
|
|
28
|
-
MlbRb.games_for_date({ date: { year: 2022, month: 3, day: 24 } })
|
|
29
|
-
MlbRb.games_for_date_range(
|
|
28
|
+
MlbRb::Games.games_for_date({ date: { year: 2022, month: 3, day: 24 } })
|
|
29
|
+
MlbRb::Games.games_for_date_range(
|
|
30
30
|
{
|
|
31
31
|
start_date: { year: 2022, month: 3, day: 23 },
|
|
32
32
|
end_date: { year: 2022, month: 3, day: 24 }
|
data/lib/mlb_rb/games.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "./lib/mlb_rb/errors"
|
|
2
|
+
require "./lib/mlb_rb/client"
|
|
3
|
+
require "./lib/mlb_rb/game"
|
|
4
|
+
|
|
5
|
+
module MlbRb
|
|
6
|
+
class Games
|
|
7
|
+
class << self
|
|
8
|
+
def games_for_date(options)
|
|
9
|
+
date = options[:date]
|
|
10
|
+
raise DateError unless validate_date(date)
|
|
11
|
+
|
|
12
|
+
client.get_games_for_date(format_date(date))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def games_for_date_range(options)
|
|
16
|
+
start_date = options[:start_date]
|
|
17
|
+
end_date = options[:end_date]
|
|
18
|
+
[start_date, end_date].each do |date|
|
|
19
|
+
raise DateError unless validate_date(date)
|
|
20
|
+
end
|
|
21
|
+
client.get_games_for_range(format_date(start_date), format_date(end_date))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def format_date(date)
|
|
27
|
+
"#{"%02d" % date[:month]}/#{"%02d" % date[:day]}/#{date[:year]}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def validate_date(date)
|
|
31
|
+
date.map do |key, value|
|
|
32
|
+
valid_number_for_date(value, key)
|
|
33
|
+
end.all?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def valid_number_for_date(date_number, type)
|
|
37
|
+
if type == :year
|
|
38
|
+
date_number.between?(1876, Date.today.year)
|
|
39
|
+
elsif type == :month
|
|
40
|
+
date_number.between?(1, 12)
|
|
41
|
+
elsif type == :day
|
|
42
|
+
date_number.between?(1, 31)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def client
|
|
47
|
+
MlbRb::Client
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/mlb_rb/version.rb
CHANGED
data/lib/mlb_rb.rb
CHANGED
|
@@ -1,59 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "./lib/mlb_rb/version"
|
|
4
|
-
require "./lib/mlb_rb/
|
|
5
|
-
require "./lib/mlb_rb/game"
|
|
4
|
+
require "./lib/mlb_rb/games"
|
|
6
5
|
|
|
7
6
|
module MlbRb
|
|
8
|
-
class Error < StandardError; end
|
|
9
|
-
|
|
10
|
-
class DateError < StandardError; end
|
|
11
|
-
|
|
12
7
|
class << self
|
|
13
8
|
def healthcheck
|
|
14
9
|
"Yup, everything is fine"
|
|
15
10
|
end
|
|
16
|
-
|
|
17
|
-
def games_for_date(options)
|
|
18
|
-
date = options[:date]
|
|
19
|
-
raise DateError unless validate_date(date)
|
|
20
|
-
|
|
21
|
-
client.get_games_for_date(format_date(date))
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def games_for_date_range(options)
|
|
25
|
-
start_date = options[:start_date]
|
|
26
|
-
end_date = options[:end_date]
|
|
27
|
-
[start_date, end_date].each do |date|
|
|
28
|
-
raise DateError unless validate_date(date)
|
|
29
|
-
end
|
|
30
|
-
client.get_games_for_range(format_date(start_date), format_date(end_date))
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def format_date(date)
|
|
36
|
-
"#{"%02d" % date[:month]}/#{"%02d" % date[:day]}/#{date[:year]}"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def validate_date(date)
|
|
40
|
-
date.map do |key, value|
|
|
41
|
-
valid_number_for_date(value, key)
|
|
42
|
-
end.all?
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def valid_number_for_date(date_number, type)
|
|
46
|
-
if type == :year
|
|
47
|
-
date_number.between?(1876, Date.today.year)
|
|
48
|
-
elsif type == :month
|
|
49
|
-
date_number.between?(1, 12)
|
|
50
|
-
elsif type == :day
|
|
51
|
-
date_number.between?(1, 31)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def client
|
|
56
|
-
MlbRb::Client
|
|
57
|
-
end
|
|
58
11
|
end
|
|
59
12
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mlb_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mark Miranda
|
|
@@ -30,7 +30,9 @@ files:
|
|
|
30
30
|
- bin/setup
|
|
31
31
|
- lib/mlb_rb.rb
|
|
32
32
|
- lib/mlb_rb/client.rb
|
|
33
|
+
- lib/mlb_rb/errors.rb
|
|
33
34
|
- lib/mlb_rb/game.rb
|
|
35
|
+
- lib/mlb_rb/games.rb
|
|
34
36
|
- lib/mlb_rb/team.rb
|
|
35
37
|
- lib/mlb_rb/version.rb
|
|
36
38
|
- mlb_rb.gemspec
|