chgk_rating 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/Gemfile +3 -1
  4. data/LICENSE +1 -1
  5. data/README.md +4 -4
  6. data/Rakefile +4 -2
  7. data/chgk_rating.gemspec +19 -12
  8. data/lib/chgk_rating/attribute_mappings.rb +107 -108
  9. data/lib/chgk_rating/chgk_object.rb +5 -1
  10. data/lib/chgk_rating/client.rb +4 -2
  11. data/lib/chgk_rating/collections/base.rb +20 -15
  12. data/lib/chgk_rating/collections/players.rb +3 -1
  13. data/lib/chgk_rating/collections/ratings/player_ratings.rb +3 -1
  14. data/lib/chgk_rating/collections/ratings/team_ratings.rb +3 -1
  15. data/lib/chgk_rating/collections/recaps.rb +4 -2
  16. data/lib/chgk_rating/collections/teams.rb +3 -1
  17. data/lib/chgk_rating/collections/tournaments/player_tournaments.rb +12 -8
  18. data/lib/chgk_rating/collections/tournaments/tournament_team_players.rb +3 -1
  19. data/lib/chgk_rating/collections/tournaments/tournament_team_results.rb +3 -1
  20. data/lib/chgk_rating/collections/tournaments/tournament_teams.rb +4 -1
  21. data/lib/chgk_rating/collections/tournaments/tournaments.rb +12 -8
  22. data/lib/chgk_rating/concerns/searching.rb +10 -9
  23. data/lib/chgk_rating/connection.rb +10 -8
  24. data/lib/chgk_rating/error.rb +7 -5
  25. data/lib/chgk_rating/models/base.rb +23 -16
  26. data/lib/chgk_rating/models/player.rb +3 -1
  27. data/lib/chgk_rating/models/rating/player_rating.rb +3 -1
  28. data/lib/chgk_rating/models/rating/rating.rb +3 -1
  29. data/lib/chgk_rating/models/rating/team_rating.rb +3 -1
  30. data/lib/chgk_rating/models/recap.rb +3 -1
  31. data/lib/chgk_rating/models/team.rb +3 -1
  32. data/lib/chgk_rating/models/tournament/player_tournament.rb +3 -1
  33. data/lib/chgk_rating/models/tournament/tournament.rb +3 -1
  34. data/lib/chgk_rating/models/tournament/tournament_team.rb +3 -1
  35. data/lib/chgk_rating/models/tournament/tournament_team_player.rb +3 -1
  36. data/lib/chgk_rating/models/tournament/tournament_team_result.rb +3 -1
  37. data/lib/chgk_rating/request.rb +10 -9
  38. data/lib/chgk_rating/utils/snakecase.rb +9 -7
  39. data/lib/chgk_rating/utils/transformations.rb +42 -36
  40. data/lib/chgk_rating/version.rb +4 -2
  41. data/lib/chgk_rating.rb +3 -1
  42. data/lib/ext/date.rb +6 -8
  43. data/lib/ext/date_time.rb +4 -2
  44. data/lib/ext/uri.rb +6 -6
  45. metadata +61 -80
  46. data/spec/lib/chgk_rating/client_spec.rb +0 -247
  47. data/spec/lib/chgk_rating/collections/player_ratings_spec.rb +0 -15
  48. data/spec/lib/chgk_rating/collections/players_spec.rb +0 -45
  49. data/spec/lib/chgk_rating/collections/recaps_spec.rb +0 -21
  50. data/spec/lib/chgk_rating/collections/team_ratings_spec.rb +0 -25
  51. data/spec/lib/chgk_rating/collections/teams_spec.rb +0 -42
  52. data/spec/lib/chgk_rating/collections/tournaments/player_tournaments_spec.rb +0 -38
  53. data/spec/lib/chgk_rating/collections/tournaments/tournament_team_players_spec.rb +0 -18
  54. data/spec/lib/chgk_rating/collections/tournaments/tournament_team_results_spec.rb +0 -17
  55. data/spec/lib/chgk_rating/collections/tournaments/tournament_teams_spec.rb +0 -58
  56. data/spec/lib/chgk_rating/collections/tournaments/tournaments_spec.rb +0 -62
  57. data/spec/lib/chgk_rating/models/base_spec.rb +0 -34
  58. data/spec/lib/chgk_rating/models/player_rating_spec.rb +0 -22
  59. data/spec/lib/chgk_rating/models/player_spec.rb +0 -62
  60. data/spec/lib/chgk_rating/models/recap_spec.rb +0 -35
  61. data/spec/lib/chgk_rating/models/team_rating_spec.rb +0 -27
  62. data/spec/lib/chgk_rating/models/team_spec.rb +0 -97
  63. data/spec/lib/chgk_rating/models/tournament/tournament_spec.rb +0 -95
  64. data/spec/lib/chgk_rating/models/tournament/tournament_team_player_spec.rb +0 -21
  65. data/spec/lib/chgk_rating/models/tournament/tournament_team_result_spec.rb +0 -19
  66. data/spec/lib/chgk_rating/models/tournament/tournament_team_spec.rb +0 -36
  67. data/spec/lib/chgk_rating/utils/snakecase_spec.rb +0 -12
  68. data/spec/lib/chgk_rating/utils/transformations_spec.rb +0 -16
  69. data/spec/lib/chgk_rating_spec.rb +0 -5
  70. data/spec/lib/ext/date_spec.rb +0 -7
  71. data/spec/lib/ext/date_time_spec.rb +0 -11
  72. data/spec/lib/ext/uri_spec.rb +0 -7
  73. data/spec/spec_helper.rb +0 -15
  74. data/spec/support/shared_examples.rb +0 -63
  75. data/spec/support/test_client.rb +0 -6
  76. data/spec/support/vcr.rb +0 -11
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class TournamentTeams < Base
4
6
  attr_reader :tournament
7
+
5
8
  def initialize(params = {})
6
9
  @tournament = build_model params[:tournament], ChgkRating::Models::Tournament
7
10
 
@@ -19,4 +22,4 @@ module ChgkRating
19
22
  end
20
23
  end
21
24
  end
22
- end
25
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Collections
3
5
  class Tournaments < Base
@@ -7,18 +9,18 @@ module ChgkRating
7
9
  @team = build_model params[:team]
8
10
 
9
11
  @season_id = params[:season_id]
10
- params.merge!(lazy: true) if @team || @season_id
12
+ params[:lazy] = true if @team || @season_id
11
13
  super
12
14
  end
13
15
 
14
16
  def revert_to_hash(key, values)
15
17
  [
16
- key,
17
- {
18
- 'idteam' => @team&.id.to_s,
19
- 'idseason' => key,
20
- 'tournaments' => values.map(&:to_h)
21
- }
18
+ key,
19
+ {
20
+ 'idteam' => @team&.id.to_s,
21
+ 'idseason' => key,
22
+ 'tournaments' => values.map(&:to_h)
23
+ }
22
24
  ]
23
25
  end
24
26
 
@@ -39,10 +41,12 @@ module ChgkRating
39
41
  def api_path
40
42
  path = 'tournaments'
41
43
  return path unless @team
44
+
42
45
  path = "teams/#{@team.id}/#{path}"
43
46
  return path unless @season_id
47
+
44
48
  path + "/#{@season_id}"
45
49
  end
46
50
  end
47
51
  end
48
- end
52
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Concerns
3
5
  module Searching
@@ -5,21 +7,20 @@ module ChgkRating
5
7
  # Creates a Search child class of a given class that changes the URI where the
6
8
  # GET request should be sent
7
9
  def self.included(klass)
8
- klass.const_set('Search',
9
- Class.new(klass) do |*_args|
10
- def api_path
11
- super + '/search'
12
- end
13
- end
14
- )
10
+ klass.const_set(:Search,
11
+ Class.new(klass) do |*_args|
12
+ def api_path
13
+ "#{super}/search"
14
+ end
15
+ end)
15
16
 
16
17
  # The actual method to perform searching
17
18
  # Instantiates a Search class with the given search params
18
19
  # and send a GET request to the proper URI (defined above)
19
20
  klass.define_singleton_method :search do |params|
20
- klass.const_get('Search').new(params)
21
+ klass.const_get(:Search).new(params)
21
22
  end
22
23
  end
23
24
  end
24
25
  end
25
- end
26
+ end
@@ -1,20 +1,22 @@
1
- require 'faraday_middleware'
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday/follow_redirects'
2
4
 
3
5
  module ChgkRating
4
6
  module Connection
5
- BASE_URL = 'http://rating.chgk.info/api'.freeze
7
+ BASE_URL = 'http://rating.chgk.info/api'
6
8
 
7
9
  def connection
8
10
  options = {
9
- headers: {
10
- accept: 'application/json',
11
- user_agent: "chgk_rating ruby gem/#{ChgkRating::VERSION}"
12
- },
13
- url: BASE_URL + '/'
11
+ headers: {
12
+ accept: 'application/json',
13
+ user_agent: "chgk_rating ruby gem/#{ChgkRating::VERSION}"
14
+ },
15
+ url: "#{BASE_URL}/"
14
16
  }
15
17
 
16
18
  Faraday.new options do |faraday|
17
- faraday.use FaradayMiddleware::FollowRedirects
19
+ faraday.use Faraday::FollowRedirects::Middleware
18
20
  faraday.adapter Faraday.default_adapter
19
21
  end
20
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  class Error < StandardError
3
5
  ClientError = Class.new(self)
@@ -26,10 +28,10 @@ module ChgkRating
26
28
  NotImplemented = Class.new(ServerError)
27
29
 
28
30
  ERRORS = {
29
- 400 => ChgkRating::Error::BadRequest,
30
- 404 => ChgkRating::Error::NotFound,
31
- 501 => ChgkRating::Error::NotImplemented
32
- }
31
+ 400 => ChgkRating::Error::BadRequest,
32
+ 404 => ChgkRating::Error::NotFound,
33
+ 501 => ChgkRating::Error::NotImplemented
34
+ }.freeze
33
35
 
34
36
  class << self
35
37
  # Create a new error from an HTTP response
@@ -43,4 +45,4 @@ module ChgkRating
43
45
  super(message)
44
46
  end
45
47
  end
46
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class Base < ChgkObject
@@ -24,7 +26,8 @@ module ChgkRating
24
26
  # Set `force` to reload data even if it is already present.
25
27
  def eager_load!(force = false)
26
28
  return unless @lazy || force
27
- extract_from raw_by(self.id)
29
+
30
+ extract_from raw_by(id)
28
31
  @lazy = false
29
32
  self
30
33
  end
@@ -36,29 +39,31 @@ module ChgkRating
36
39
  end
37
40
 
38
41
  def self.no_lazy_support!
39
- self.const_set :NO_LAZY_SUPPORT, true
42
+ const_set :NO_LAZY_SUPPORT, true
40
43
  undef_method :lazy
41
44
  end
42
45
 
43
46
  def to_h
44
- self.class.attribute_mapping.inject({}) do |memo, (attr, mapping)|
45
- data = self.send attr
46
- data = mapping[:transform_down].call(data) if mapping.has_key?(:transform_down)
47
- memo[ mapping[:raw_name] ] = data
48
- memo
47
+ self.class.attribute_mapping.each_with_object({}) do |(attr, mapping), memo|
48
+ data = send attr
49
+ data = mapping[:transform_down].call(data) if mapping.key?(:transform_down)
50
+ memo[mapping[:raw_name]] = data
49
51
  end
50
52
  end
51
53
 
52
- private
54
+ class << self
55
+ # Grab the attribute mapping for the class and its superclass
56
+ # (as superclass may present common mappings for multiple classes)
57
+ def attribute_mapping
58
+ return nil unless name
53
59
 
54
- # Grab the attribute mapping for the class and its superclass
55
- # (as superclass may present common mappings for multiple classes)
56
- def self.attribute_mapping
57
- return nil unless self.name
58
- ChgkRating::AttributeMappings.find(self.name).
59
- merge(ChgkRating::AttributeMappings.find(self.superclass.name))
60
+ ChgkRating::AttributeMappings.find(name).
61
+ merge(ChgkRating::AttributeMappings.find(superclass.name))
62
+ end
60
63
  end
61
64
 
65
+ private
66
+
62
67
  def lazy_load?(params)
63
68
  self.class.const_defined?(:NO_LAZY_SUPPORT) ? false : params[:lazy]
64
69
  end
@@ -85,16 +90,18 @@ module ChgkRating
85
90
  self.class.attribute_mapping.each do |attr, mapping|
86
91
  data = get_data_from raw_data, attr, mapping
87
92
  next unless data
93
+
88
94
  instance_variable_set "@#{attr}", transform_up(data, mapping)
89
95
  end
90
96
  end
91
97
 
92
98
  def get_data_from(raw, attr, mapping)
93
- raw.is_a?(self.class) ? raw.send(attr) : raw[ mapping[:raw_name] ]
99
+ raw.is_a?(self.class) ? raw.send(attr) : raw[mapping[:raw_name]]
94
100
  end
95
101
 
96
102
  def transform_up(data, mapping)
97
- return data unless mapping.has_key?(:transform_up)
103
+ return data unless mapping.key?(:transform_up)
104
+
98
105
  mapping[:transform_up].call(data)
99
106
  end
100
107
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class Player < Base
@@ -33,4 +35,4 @@ module ChgkRating
33
35
  end
34
36
  end
35
37
  end
36
- end
38
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class PlayerRating < Rating
@@ -13,4 +15,4 @@ module ChgkRating
13
15
  end
14
16
  end
15
17
  end
16
- end
18
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class Rating < Base
@@ -5,4 +7,4 @@ module ChgkRating
5
7
  no_lazy_support!
6
8
  end
7
9
  end
8
- end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class TeamRating < Rating
@@ -13,4 +15,4 @@ module ChgkRating
13
15
  end
14
16
  end
15
17
  end
16
- end
18
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class Recap < Base
@@ -16,4 +18,4 @@ module ChgkRating
16
18
  end
17
19
  end
18
20
  end
19
- end
21
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class Team < Base
@@ -59,4 +61,4 @@ module ChgkRating
59
61
  end
60
62
  end
61
63
  end
62
- end
64
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class PlayerTournament < Base
@@ -5,4 +7,4 @@ module ChgkRating
5
7
  no_lazy_support!
6
8
  end
7
9
  end
8
- end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class Tournament < Base
@@ -43,4 +45,4 @@ module ChgkRating
43
45
  end
44
46
  end
45
47
  end
46
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class TournamentTeam < Base
@@ -26,4 +28,4 @@ module ChgkRating
26
28
  end
27
29
  end
28
30
  end
29
- end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class TournamentTeamPlayer < Base
@@ -5,4 +7,4 @@ module ChgkRating
5
7
  no_lazy_support!
6
8
  end
7
9
  end
8
- end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Models
3
5
  class TournamentTeamResult < Base
@@ -5,4 +7,4 @@ module ChgkRating
5
7
  no_lazy_support!
6
8
  end
7
9
  end
8
- end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Request
3
5
  include ChgkRating::Connection
@@ -16,17 +18,16 @@ module ChgkRating
16
18
  end
17
19
 
18
20
  def respond(response)
19
- begin
20
- body = MultiJson.load response.body
21
- raise MultiJson::ParseError if body.respond_to?(:has_key?) && body.has_key?('error')
22
- body
23
- rescue MultiJson::ParseError
24
- respond_with_error response.status, response.body
25
- end
21
+ body = MultiJson.load response.body
22
+ raise MultiJson::ParseError if body.respond_to?(:has_key?) && body.key?('error')
23
+
24
+ body
25
+ rescue MultiJson::ParseError
26
+ respond_with_error response.status, response.body
26
27
  end
27
28
 
28
29
  def respond_with_error(code, body)
29
- fail ChgkRating::Error::ERRORS[code].from_response(body)
30
+ raise ChgkRating::Error::ERRORS[code].from_response(body)
30
31
  end
31
32
  end
32
- end
33
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Initial code taken from Facets gem by Rubyworks
2
4
  # https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
3
5
 
@@ -6,11 +8,11 @@ class String
6
8
  # replaced by underscores.
7
9
  def snakecase_upcase
8
10
  split('::').last.
9
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
10
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
11
- tr('-', '_').
12
- gsub(/\s/, '_').
13
- gsub(/__+/, '_').
14
- upcase
11
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
12
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
13
+ tr('-', '_').
14
+ gsub(/\s/, '_').
15
+ gsub(/__+/, '_').
16
+ upcase
15
17
  end
16
- end
18
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
4
  module Utils
3
5
  module Transformations
@@ -6,10 +8,10 @@ module ChgkRating
6
8
  up = 'integer' if up.nil? || up.empty?
7
9
  down = 'string' if down.nil? || down.empty?
8
10
 
9
- %i(up down).inject({}) do |result, t|
11
+ %i[up down].reduce({}) do |result, t|
10
12
  current_transformer = binding.local_variable_get t
11
13
  result.merge({
12
- "transform_#{t}".to_sym => send(current_transformer)
14
+ "transform_#{t}".to_sym => send(current_transformer)
13
15
  })
14
16
  end
15
17
  end
@@ -24,10 +26,12 @@ module ChgkRating
24
26
  private
25
27
 
26
28
  def chgk_object(namespace, type = 'Models')
27
- ->(d) do
28
- opts = type == 'Models' ?
29
- [d, {lazy: true}] :
30
- [{collection: d, lazy: true}]
29
+ lambda do |d|
30
+ opts = if type == 'Models'
31
+ [d, {lazy: true}]
32
+ else
33
+ [{collection: d, lazy: true}]
34
+ end
31
35
 
32
36
  Module.const_get("ChgkRating::#{type}::#{namespace}").new(*opts)
33
37
  end
@@ -42,43 +46,45 @@ module ChgkRating
42
46
  end
43
47
 
44
48
  def to_star(method = :to_s, iterate = false)
45
- ->(d) do
46
- iterate ?
47
- d.map {|obj| obj.send method } :
48
- d.send(method)
49
+ lambda do |d|
50
+ if iterate
51
+ d.map { |obj| obj.send method }
52
+ else
53
+ d.send(method)
54
+ end
49
55
  end
50
56
  end
51
57
  end
52
58
 
53
59
  TRANSFORMERS = {
54
- string: to_star,
55
- integer: to_star(:to_i),
56
- float: to_star(:to_f),
57
- id: to_star(:id),
58
- ids: to_star(:id, true),
59
- sym: to_star(:to_sym),
60
- strdate: to_star(:to_s_chgk),
61
- uri: ->(d) { URI.parse_safely d },
62
- boolean: to_boolean,
63
- binboolean: to_binary_boolean,
64
- date: ->(d) { Date.parse_safely d},
65
- datetime: ->(d) { DateTime.parse_safely d},
66
- splitboolean: ->(d) do
67
- d&.split('')&.map {|result| to_boolean.call(result)}
68
- end,
69
- arraystrboolean: ->(d) do
70
- d&.map {|result| to_binary_boolean.call(result)}
71
- end,
72
- arrayboolean: ->(d) do
73
- d&.map {|result| to_boolean.call(result)}
74
- end,
75
- team: chgk_object('Team'),
76
- tournament: chgk_object('Tournament'),
77
- player: chgk_object('Player'),
78
- players: chgk_object('Players', 'Collections')
60
+ string: to_star,
61
+ integer: to_star(:to_i),
62
+ float: to_star(:to_f),
63
+ id: to_star(:id),
64
+ ids: to_star(:id, true),
65
+ sym: to_star(:to_sym),
66
+ strdate: to_star(:to_s_chgk),
67
+ uri: ->(d) { URI.parse_safely d },
68
+ boolean: to_boolean,
69
+ binboolean: to_binary_boolean,
70
+ date: ->(d) { Date.parse_safely d },
71
+ datetime: ->(d) { DateTime.parse_safely d },
72
+ splitboolean: lambda do |d|
73
+ d&.split('')&.map { |result| to_boolean.call(result) }
74
+ end,
75
+ arraystrboolean: lambda do |d|
76
+ d&.map { |result| to_binary_boolean.call(result) }
77
+ end,
78
+ arrayboolean: lambda do |d|
79
+ d&.map { |result| to_boolean.call(result) }
80
+ end,
81
+ team: chgk_object('Team'),
82
+ tournament: chgk_object('Tournament'),
83
+ player: chgk_object('Player'),
84
+ players: chgk_object('Players', 'Collections')
79
85
  }.freeze
80
86
 
81
87
  load_transformers!
82
88
  end
83
89
  end
84
- end
90
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ChgkRating
2
- VERSION = '2.1.0'.freeze
3
- end
4
+ VERSION = '2.2.0'
5
+ end
data/lib/chgk_rating.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require 'uri'
3
5
  require 'faraday'
@@ -54,4 +56,4 @@ module ChgkRating
54
56
  def self.client
55
57
  @client ||= ChgkRating::Client.new
56
58
  end
57
- end
59
+ end
data/lib/ext/date.rb CHANGED
@@ -1,11 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Date
2
4
  def self.parse_safely(raw_date_time)
3
- begin
4
- self.parse raw_date_time
5
- rescue ArgumentError
6
- nil
7
- rescue TypeError
8
- nil
9
- end
5
+ parse raw_date_time
6
+ rescue ArgumentError, TypeError
7
+ nil
10
8
  end
11
- end
9
+ end
data/lib/ext/date_time.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DateTime
2
4
  def to_s_chgk
3
- self.strftime('%Y-%m-%d %H:%M:%S')
5
+ strftime('%Y-%m-%d %H:%M:%S')
4
6
  end
5
- end
7
+ end
data/lib/ext/uri.rb CHANGED
@@ -1,9 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module URI
2
4
  def self.parse_safely(raw_uri)
3
- begin
4
- URI.parse raw_uri
5
- rescue URI::InvalidURIError
6
- nil
7
- end
5
+ URI.parse raw_uri
6
+ rescue URI::InvalidURIError
7
+ nil
8
8
  end
9
- end
9
+ end