gravaty 10.0.0 → 11.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +7 -0
  3. data/Gemfile +5 -1
  4. data/README.md +219 -212
  5. data/Rakefile +9 -3
  6. data/copyright.md +33 -136
  7. data/examples/avatar.rb +70 -43
  8. data/examples/basics.rb +30 -20
  9. data/examples/profile.rb +77 -50
  10. data/examples/xmlrpc.rb +24 -10
  11. data/gravaty.gemspec +46 -25
  12. data/html/CHANGELOG.html +13 -20
  13. data/html/COPYING_md.html +8 -24
  14. data/html/Gemfile.html +7 -21
  15. data/html/Gravaty.html +49 -113
  16. data/html/Gravaty/Gravaty.html +138 -343
  17. data/html/Gravaty/ParsableDuckType.html +14 -33
  18. data/html/Gravaty/Parser.html +27 -66
  19. data/html/Gravaty/Parsers.html +3 -11
  20. data/html/Gravaty/Parsers/Avatar.html +19 -36
  21. data/html/Gravaty/Parsers/Callback.html +21 -37
  22. data/html/Gravaty/Parsers/Default.html +28 -45
  23. data/html/Gravaty/Parsers/Force.html +21 -37
  24. data/html/Gravaty/Parsers/Format.html +22 -42
  25. data/html/Gravaty/Parsers/Pixelsize.html +22 -42
  26. data/html/Gravaty/Parsers/Rating.html +22 -42
  27. data/html/Gravaty/Parsers/Secure.html +19 -36
  28. data/html/Gravaty/Parsers/Type.html +22 -42
  29. data/html/Gravaty/Utils.html +11 -13
  30. data/html/Gravaty/Utils/Downloader.html +3 -11
  31. data/html/Gravaty/Utils/Downloader/Downloader.html +25 -59
  32. data/html/Gravaty/Utils/Raisers.html +24 -55
  33. data/html/Gravaty/Utils/Rfc5322.html +12 -19
  34. data/html/Gravaty/Utils/RpcConnector.html +11 -13
  35. data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +33 -73
  36. data/html/Object.html +728 -57
  37. data/html/README_md.html +105 -100
  38. data/html/Rakefile.html +9 -23
  39. data/html/copyright_md.html +17 -119
  40. data/html/created.rid +48 -55
  41. data/html/css/rdoc.css +1 -1
  42. data/html/index.html +97 -114
  43. data/html/js/navigation.js.gz +0 -0
  44. data/html/js/search_index.js +1 -1
  45. data/html/js/search_index.js.gz +0 -0
  46. data/html/js/searcher.js.gz +0 -0
  47. data/html/table_of_contents.html +219 -651
  48. data/lib/gravaty.rb +22 -15
  49. data/lib/gravaty/application.rb +40 -25
  50. data/lib/gravaty/constants.rb +20 -11
  51. data/lib/gravaty/locales/en.yml +9 -3
  52. data/lib/gravaty/locales/it.yml +9 -3
  53. data/lib/gravaty/locales/ja.yml +7 -4
  54. data/lib/gravaty/parser.rb +16 -10
  55. data/lib/gravaty/parsers/avatar.rb +11 -3
  56. data/lib/gravaty/parsers/callback.rb +13 -4
  57. data/lib/gravaty/parsers/default.rb +24 -16
  58. data/lib/gravaty/parsers/force.rb +12 -2
  59. data/lib/gravaty/parsers/format.rb +11 -2
  60. data/lib/gravaty/parsers/pixelsize.rb +12 -3
  61. data/lib/gravaty/parsers/rating.rb +12 -3
  62. data/lib/gravaty/parsers/secure.rb +11 -2
  63. data/lib/gravaty/parsers/type.rb +11 -2
  64. data/lib/gravaty/utils/downloader.rb +98 -96
  65. data/lib/gravaty/utils/raisers.rb +19 -12
  66. data/lib/gravaty/utils/rfc5322.rb +54 -41
  67. data/lib/gravaty/utils/rpc_connector.rb +19 -11
  68. data/lib/gravaty/version.rb +10 -2
  69. data/test/gravaty/locales/en.yml +29 -0
  70. data/test/gravaty/locales/it.yml +29 -0
  71. data/test/gravaty/locales/ja.yml +27 -0
  72. data/test/gravaty/locales/test_locales.rb +17 -13
  73. data/test/gravaty/parsers/test_avatar.rb +9 -1
  74. data/test/gravaty/parsers/test_callback.rb +12 -4
  75. data/test/gravaty/parsers/test_default.rb +25 -21
  76. data/test/gravaty/parsers/test_force.rb +9 -1
  77. data/test/gravaty/parsers/test_format.rb +18 -11
  78. data/test/gravaty/parsers/test_pixelsize.rb +19 -12
  79. data/test/gravaty/parsers/test_rating.rb +18 -11
  80. data/test/gravaty/parsers/test_secure.rb +9 -1
  81. data/test/gravaty/parsers/test_type.rb +14 -5
  82. data/test/gravaty/test_application.rb +14 -6
  83. data/test/gravaty/test_avatar.rb +94 -59
  84. data/test/gravaty/test_parser.rb +11 -5
  85. data/test/gravaty/test_profile.rb +47 -25
  86. data/test/gravaty/utils/test_downloader.rb +43 -28
  87. data/test/gravaty/utils/test_raisers.rb +42 -26
  88. data/test/gravaty/utils/test_rfc5322.rb +35 -13
  89. data/test/gravaty/utils/test_rpc_connector.rb +83 -39
  90. data/test/test_gravaty.rb +12 -4
  91. data/test/test_helper.rb +15 -9
  92. metadata +54 -40
  93. data/ISSUES.md +0 -62
  94. data/acknowledgements.md +0 -66
  95. data/authors.md +0 -63
  96. data/examples/cacert.pem +0 -3466
  97. data/html/ISSUES_md.html +0 -166
  98. data/html/acknowledgements_md.html +0 -161
  99. data/html/authors_md.html +0 -174
  100. data/html/examples/cacert_pem.html +0 -1078
data/lib/gravaty.rb CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # gravaty
3
- # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
5
+ # rubocop:disable Style/AsciiComments
6
+ # © 2013 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of gravaty.
6
10
  #
@@ -16,6 +20,10 @@
16
20
  #
17
21
  # You should have received a copy of the GNU General Public License
18
22
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
23
+ #
24
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
25
+ #
26
+ # SPDX-License-Identifier: GPL-3.0-or-later
19
27
  #++
20
28
 
21
29
  require 'digest/md5'
@@ -35,10 +43,11 @@ require_relative 'gravaty/parsers/secure'
35
43
  require_relative 'gravaty/parsers/type'
36
44
 
37
45
  # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
46
+ # rubocop:disable Style/AsciiComments
38
47
  # Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
48
+ # rubocop:enable Style/AsciiComments
39
49
  # License:: GNU General Public License version 3
40
50
  module Gravaty
41
-
42
51
  # Creates a new Gravaty described by the user's +email+. Throws a
43
52
  # <code>ArgumentError</code> exception if the supplied +email+ address
44
53
  # is nil or not valid according to RFC5322.
@@ -55,21 +64,19 @@ module Gravaty
55
64
  Gravaty.new email_address, parser
56
65
  end
57
66
 
58
- # ------------------------------ here starts the list of private methods
59
-
60
- private
67
+ # ------------------------------ here starts the list of private methods
61
68
 
62
- # Provides the parameters' parsers object.
69
+ # Provides the parameters' parsers object.
63
70
  def self.parser
64
- parsers = {avatar: Parsers::Avatar.new,
65
- callback: Parsers::Callback.new,
66
- default: Parsers::Default.new,
67
- force: Parsers::Force.new,
68
- format: Parsers::Format.new,
69
- pixelsize: Parsers::Pixelsize.new,
70
- rating: Parsers::Rating.new,
71
- secure: Parsers::Secure.new,
72
- type: Parsers::Type.new}
71
+ parsers = { avatar: Parsers::Avatar.new,
72
+ callback: Parsers::Callback.new,
73
+ default: Parsers::Default.new,
74
+ force: Parsers::Force.new,
75
+ format: Parsers::Format.new,
76
+ pixelsize: Parsers::Pixelsize.new,
77
+ rating: Parsers::Rating.new,
78
+ secure: Parsers::Secure.new,
79
+ type: Parsers::Type.new }
73
80
 
74
81
  Parser.new parsers
75
82
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # gravaty
3
- # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
5
+ # rubocop:disable Style/AsciiComments
6
+ # © 2013 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of gravaty.
6
10
  #
@@ -16,6 +20,10 @@
16
20
  #
17
21
  # You should have received a copy of the GNU General Public License
18
22
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
23
+ #
24
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
25
+ #
26
+ # SPDX-License-Identifier: GPL-3.0-or-later
19
27
  #++
20
28
 
21
29
  require 'digest'
@@ -29,13 +37,14 @@ require_relative 'utils/rfc5322'
29
37
  require_relative 'utils/rpc_connector'
30
38
 
31
39
  module Gravaty
32
-
33
40
  # This class is a simple API to retrieve an URL with specified options
34
41
  # from Gravatar site. It can be used to read data for avatars,
35
42
  # profiles or for XML-RPC APi calls. The only needed parameter to
36
43
  # create a Gravaty object is the reference +email+ address.
37
44
  # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
45
+ # rubocop:disable Style/AsciiComments
38
46
  # Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
47
+ # rubocop:enable Style/AsciiComments
39
48
  # License:: GNU General Public License version 3
40
49
  class Gravaty
41
50
  include Comparable
@@ -66,7 +75,9 @@ module Gravaty
66
75
  '/locales/', '*.yml')]
67
76
 
68
77
  raise ArgumentError, I18n.t('error.nil') if email_address.nil?
69
- raise ArgumentError, I18n.t('error.invalid', value: email_address) unless Utils::Rfc5322::EMAIL.match email_address # thanks Peter!
78
+ unless Utils::Rfc5322::EMAIL.match email_address
79
+ raise ArgumentError, I18n.t('error.invalid', value: email_address)
80
+ end
70
81
 
71
82
  @email = email_address.strip.downcase
72
83
  @digest = Digest::MD5.hexdigest email
@@ -124,13 +135,13 @@ module Gravaty
124
135
  type = args.fetch(:type, nil)
125
136
  secure = args.fetch(:secure, secure)
126
137
 
127
- [:pixelsize, :force, :default, :rating].each do |param|
138
+ %i[pixelsize force default rating].each do |param|
128
139
  array << @parser.parse(param.to_s, args[param]) unless args[param].nil?
129
140
  end
130
141
  end
131
142
 
132
- build_uri(secure, true) + digest +
133
- @parser.parse('type', type) + build_query_string(array)
143
+ build_uri(secure: secure) + digest +
144
+ @parser.parse('type', type) + build_query_string(array)
134
145
  end
135
146
 
136
147
  # See avatar method. This banged version saves the resulting string
@@ -167,15 +178,15 @@ module Gravaty
167
178
  format = args[:format].downcase unless args[:format].nil?
168
179
  secure = args.fetch(:secure, secure)
169
180
 
170
- unless (format.nil?) and (PROFILES.include? format)
181
+ unless format.nil? && (PROFILES.include? format)
171
182
  selected = (format == 'json' ? 'callback' : 'pixelsize')
172
183
 
173
184
  array << @parser.parse(selected, args[selected.to_sym]) unless args[selected.to_sym].nil?
174
185
  end
175
186
  end
176
187
 
177
- build_uri(secure, false) + digest +
178
- @parser.parse('format', format) + build_query_string(array)
188
+ build_uri(secure: secure, avatar: false) + digest +
189
+ @parser.parse(:format, format) + build_query_string(array)
179
190
  end
180
191
 
181
192
  # See profile method. This banged version saves the resulting string
@@ -193,10 +204,12 @@ module Gravaty
193
204
  # Params::
194
205
  # - +filename+: [String] is the filename to be saved.
195
206
  def download(filename = nil)
196
- filename = URI.parse(@gravaty).path.rpartition('/')
197
- .last if filename.nil?
207
+ if filename.nil?
208
+ filename = URI.parse(@gravaty).path.rpartition('/')
209
+ .last
210
+ end
198
211
  Utils::Downloader::Downloader
199
- .download_file @gravaty, filename # thanks Jon!
212
+ .download_file @gravaty, filename # thanks Jon!
200
213
  end
201
214
 
202
215
  # See profile method. Customized version for QRCode-specific
@@ -292,9 +305,11 @@ module Gravaty
292
305
  raise ArgumentError, I18n.t('error.nil') if password.nil?
293
306
  raise ArgumentError, I18n.t('error.invalid', value: a_method) unless RPC_METHODS.include? a_method
294
307
 
295
- @rpc_connector = Utils::RpcConnector::RpcConnector
296
- .new(digest, password) if @rpc_connector.nil?
297
- @rpc_connector.call a_method, args unless @rpc_connector.nil?
308
+ if @rpc_connector.nil?
309
+ @rpc_connector = Utils::RpcConnector::RpcConnector
310
+ .new(digest, password)
311
+ end
312
+ @rpc_connector&.call a_method, args
298
313
  end
299
314
 
300
315
  # Returns a JSon object representing the Gravaty object.
@@ -304,8 +319,8 @@ module Gravaty
304
319
  # - <tt>a_json = new_gravaty.to_json</tt>
305
320
  # Returns:: a +JSON+ containing the Gravaty object representation
306
321
  # with currently saved options and configuration parameters.
307
- def to_json
308
- result = Hash.new
322
+ def to_json(*_args)
323
+ result = {}
309
324
  result[email] = digest
310
325
 
311
326
  result.to_json
@@ -322,8 +337,8 @@ module Gravaty
322
337
  @gravaty.to_s
323
338
  end
324
339
 
325
- def <=>(other_gravaty)
326
- @email <=> other_gravaty.email
340
+ def <=>(other)
341
+ @email <=> other.email
327
342
  end
328
343
 
329
344
  # -------------------------- here starts the list of private methods
@@ -336,18 +351,18 @@ module Gravaty
336
351
 
337
352
  unless params_array.nil?
338
353
  parameters = params_array.reject { |p| p.nil? or p.empty? }
339
- .join('&')
354
+ .join('&')
340
355
  end
341
356
 
342
- return ('?' + parameters) unless parameters.nil? or parameters
343
- .empty?
357
+ return "?#{parameters}" unless parameters.nil? || parameters
358
+ .empty?
359
+
344
360
  ''
345
361
  end
346
362
 
347
363
  # Return the basic URI structure according to type and security.
348
- def build_uri(secure = false, avatar = true)
349
- @parser.parse('secure', secure) + '.gravatar.com/' +
350
- @parser.parse('avatar', avatar)
364
+ def build_uri(secure: false, avatar: true)
365
+ "#{@parser.parse('secure', secure)}.gravatar.com/#{@parser.parse('avatar', avatar)}"
351
366
  end
352
367
  end
353
368
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # gravaty
3
- # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
5
+ # rubocop:disable Style/AsciiComments
6
+ # © 2013 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of gravaty.
6
10
  #
@@ -16,6 +20,10 @@
16
20
  #
17
21
  # You should have received a copy of the GNU General Public License
18
22
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
23
+ #
24
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
25
+ #
26
+ # SPDX-License-Identifier: GPL-3.0-or-later
19
27
  #++
20
28
 
21
29
  module Gravaty
@@ -25,37 +33,38 @@ module Gravaty
25
33
 
26
34
  # Allowed parameters names. Currently: avatar, callback, default,
27
35
  # force, format, pixelsize, rating, secure and type.
28
- ALLOWED_PARAMS = [:avatar, :callback, :default, :force, :format,
29
- :pixelsize, :rating, :secure, :type]
36
+ ALLOWED_PARAMS = %i[avatar callback default force format
37
+ pixelsize rating secure type].freeze
30
38
 
31
39
  # Allowed formats (extensions) for avatar requests. Currently:
32
40
  # jp(e)g, png and gif.
33
- AVATAR_FORMATS = %w(jpg jpeg png gif)
41
+ AVATAR_FORMATS = %w[jpg jpeg png gif].freeze
34
42
 
35
43
  # Currently allowed default builtin options. Currently: 404, mp,
36
44
  # identicon, monsterid,wavatar, retro, robohash and blank.
37
- DEFAULT_OPTIONS = %w(404 mp identicon monsterid wavatar retro robohash blank)
45
+ DEFAULT_OPTIONS = %w[404 mp identicon monsterid wavatar retro robohash blank].freeze
38
46
 
39
47
  # Allowed formats (extensions) for default own images. Currently:
40
48
  # jp(e)g, png and gif.
41
- IMAGES_FORMATS = %w(jpg jpeg png gif)
49
+ IMAGES_FORMATS = %w[jpg jpeg png gif].freeze
42
50
 
43
51
  # Allowed formats (extensions) for profile requests. Currently: json,
44
52
  # xml, php, vcf and qr.
45
- PROFILE_FORMATS = %w(json xml php vcf qr)
53
+ PROFILE_FORMATS = %w[json xml php vcf qr].freeze
46
54
 
47
55
  # Formats allowing supplemental options for profile requests.
48
56
  # Currently json and qr.
49
- PROFILES = %w(json qr)
57
+ PROFILES = %w[json qr].freeze
50
58
 
51
59
  # Allowed rating options. Currently: g, pg, r and x.
52
- RATING_OPTIONS = %w(g pg r x)
60
+ RATING_OPTIONS = %w[g pg r x].freeze
53
61
 
54
62
  # Possible XML-RPC API errors.
55
- RPC_ERRORS = [-7, -8, -9, -10, -11, -100]
63
+ RPC_ERRORS = [-7, -8, -9, -10, -11, -100].freeze
56
64
 
57
65
  # Allowed XML-RPC API methods.
58
- RPC_METHODS = %w(grav.exists grav.addresses grav.userimages grav.saveData grav.saveUrl grav.useUserimage grav.removeImage grav.deleteUserimage grav.test)
66
+ RPC_METHODS = %w[grav.exists grav.addresses grav.userimages grav.saveData grav.saveUrl grav.useUserimage
67
+ grav.removeImage grav.deleteUserimage grav.test].freeze
59
68
 
60
69
  # Default test method for XML-RPC API.
61
70
  RPC_TEST_METHOD = 'grav.test'
@@ -1,5 +1,8 @@
1
+ #--
1
2
  # gravaty
2
- # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
3
+ # rubocop:disable Style/AsciiComments
4
+ # © 2013 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
3
6
  #
4
7
  # This file is part of gravaty.
5
8
  #
@@ -15,6 +18,11 @@
15
18
  #
16
19
  # You should have received a copy of the GNU General Public License
17
20
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
21
+ #
22
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
23
+ #
24
+ # SPDX-License-Identifier: GPL-3.0-or-later
25
+ #++
18
26
 
19
27
  en:
20
28
  error:
@@ -26,8 +34,6 @@ en:
26
34
  value: "Value '%{value}' is not in allowed range."
27
35
  warn:
28
36
  deprecated: This method has been deprecated.
29
- test:
30
- test: test data
31
37
  gravatar:
32
38
  errors:
33
39
  -7: Use secure.gravatar.com
@@ -1,5 +1,8 @@
1
+ #--
1
2
  # gravaty
2
- # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
3
+ # rubocop:disable Style/AsciiComments
4
+ # © 2013 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
3
6
  #
4
7
  # This file is part of gravaty.
5
8
  #
@@ -15,6 +18,11 @@
15
18
  #
16
19
  # You should have received a copy of the GNU General Public License
17
20
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
21
+ #
22
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
23
+ #
24
+ # SPDX-License-Identifier: GPL-3.0-or-later
25
+ #++
18
26
 
19
27
  it:
20
28
  error:
@@ -26,8 +34,6 @@ it:
26
34
  value: "Il valore '%{value}' non è nell'intervallo previsto."
27
35
  warn:
28
36
  deprecated: Questo metodo è obsoleto.
29
- test:
30
- test: dato di prova
31
37
  gravatar:
32
38
  errors:
33
39
  -7: Utilizzare secure.gravatar.com
@@ -1,6 +1,6 @@
1
+ #--
1
2
  # gravaty
2
- # Copyright © 2013 新部裕
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 新部裕, Marco Bresciani
3
+ # © 2013 新部裕, Marco Bresciani
4
4
  #
5
5
  # This file is part of gravaty.
6
6
  #
@@ -16,6 +16,11 @@
16
16
  #
17
17
  # You should have received a copy of the GNU General Public License
18
18
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
21
+ #
22
+ # SPDX-License-Identifier: GPL-3.0-or-later
23
+ #++
19
24
 
20
25
  ja:
21
26
  error:
@@ -27,8 +32,6 @@ ja:
27
32
  value: "値 '%{value}' が範囲外です。"
28
33
  warn:
29
34
  deprecated: このメソッドはすでに廃止され、推奨されていません。
30
- test:
31
- test: 試験データ
32
35
  gravatar:
33
36
  errors:
34
37
  -7: secure.gravatar.com を使用
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # gravaty
3
- # Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
5
+ # rubocop:disable Style/AsciiComments
6
+ # © 2013 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of gravaty.
6
10
  #
@@ -16,34 +20,36 @@
16
20
  #
17
21
  # You should have received a copy of the GNU General Public License
18
22
  # along with gravaty. If not, see <http://www.gnu.org/licenses/>.
23
+ #
24
+ # SPDX-FileCopyrightText: 2013 Marco Bresciani
25
+ #
26
+ # SPDX-License-Identifier: GPL-3.0-or-later
19
27
  #++
20
28
 
21
29
  require_relative 'constants'
22
30
 
23
31
  module Gravaty
24
-
25
32
  # This class is a simple utility that is used to parse and filter
26
33
  # parameters for gravaty.
27
34
  #
28
35
  # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
36
+ # rubocop:disable Style/AsciiComments
29
37
  # Copyright:: Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
38
+ # rubocop:enable Style/AsciiComments
30
39
  # License:: GNU General Public License version 3
31
40
  class Parser
32
41
  attr_reader :parsers
33
42
 
34
43
  def initialize(args = {})
35
- @parsers = Hash.new
36
- ALLOWED_PARAMS.each do |param|
37
- parsers[param] = args[param]
38
- end unless args.nil?
44
+ @parsers = {}
45
+ ALLOWED_PARAMS.each { |param| parsers[param] = args[param] } unless args.nil?
39
46
  end
40
47
 
41
48
  # Provides the duck type for a generic parsing object.
42
- def parse(method = nil, value = nil)
49
+ def parse(method = nil, params = nil)
43
50
  a_parser = nil
44
- a_parser = parsers[method.to_sym] unless method.nil? or
45
- parsers.nil?
46
- a_parser.parse value unless a_parser.nil?
51
+ a_parser = parsers[method.to_sym] unless method.nil? || parsers.nil?
52
+ a_parser&.parse params
47
53
  end
48
54
  end
49
55
  end