gravaty 10.0.0 → 11.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/Gemfile +5 -1
- data/README.md +219 -212
- data/Rakefile +9 -3
- data/copyright.md +33 -136
- data/examples/avatar.rb +70 -43
- data/examples/basics.rb +30 -20
- data/examples/profile.rb +77 -50
- data/examples/xmlrpc.rb +24 -10
- data/gravaty.gemspec +46 -25
- data/html/CHANGELOG.html +13 -20
- data/html/COPYING_md.html +8 -24
- data/html/Gemfile.html +7 -21
- data/html/Gravaty.html +49 -113
- data/html/Gravaty/Gravaty.html +138 -343
- data/html/Gravaty/ParsableDuckType.html +14 -33
- data/html/Gravaty/Parser.html +27 -66
- data/html/Gravaty/Parsers.html +3 -11
- data/html/Gravaty/Parsers/Avatar.html +19 -36
- data/html/Gravaty/Parsers/Callback.html +21 -37
- data/html/Gravaty/Parsers/Default.html +28 -45
- data/html/Gravaty/Parsers/Force.html +21 -37
- data/html/Gravaty/Parsers/Format.html +22 -42
- data/html/Gravaty/Parsers/Pixelsize.html +22 -42
- data/html/Gravaty/Parsers/Rating.html +22 -42
- data/html/Gravaty/Parsers/Secure.html +19 -36
- data/html/Gravaty/Parsers/Type.html +22 -42
- data/html/Gravaty/Utils.html +11 -13
- data/html/Gravaty/Utils/Downloader.html +3 -11
- data/html/Gravaty/Utils/Downloader/Downloader.html +25 -59
- data/html/Gravaty/Utils/Raisers.html +24 -55
- data/html/Gravaty/Utils/Rfc5322.html +12 -19
- data/html/Gravaty/Utils/RpcConnector.html +11 -13
- data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +33 -73
- data/html/Object.html +728 -57
- data/html/README_md.html +105 -100
- data/html/Rakefile.html +9 -23
- data/html/copyright_md.html +17 -119
- data/html/created.rid +48 -55
- data/html/css/rdoc.css +1 -1
- data/html/index.html +97 -114
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +219 -651
- data/lib/gravaty.rb +22 -15
- data/lib/gravaty/application.rb +40 -25
- data/lib/gravaty/constants.rb +20 -11
- data/lib/gravaty/locales/en.yml +9 -3
- data/lib/gravaty/locales/it.yml +9 -3
- data/lib/gravaty/locales/ja.yml +7 -4
- data/lib/gravaty/parser.rb +16 -10
- data/lib/gravaty/parsers/avatar.rb +11 -3
- data/lib/gravaty/parsers/callback.rb +13 -4
- data/lib/gravaty/parsers/default.rb +24 -16
- data/lib/gravaty/parsers/force.rb +12 -2
- data/lib/gravaty/parsers/format.rb +11 -2
- data/lib/gravaty/parsers/pixelsize.rb +12 -3
- data/lib/gravaty/parsers/rating.rb +12 -3
- data/lib/gravaty/parsers/secure.rb +11 -2
- data/lib/gravaty/parsers/type.rb +11 -2
- data/lib/gravaty/utils/downloader.rb +98 -96
- data/lib/gravaty/utils/raisers.rb +19 -12
- data/lib/gravaty/utils/rfc5322.rb +54 -41
- data/lib/gravaty/utils/rpc_connector.rb +19 -11
- data/lib/gravaty/version.rb +10 -2
- data/test/gravaty/locales/en.yml +29 -0
- data/test/gravaty/locales/it.yml +29 -0
- data/test/gravaty/locales/ja.yml +27 -0
- data/test/gravaty/locales/test_locales.rb +17 -13
- data/test/gravaty/parsers/test_avatar.rb +9 -1
- data/test/gravaty/parsers/test_callback.rb +12 -4
- data/test/gravaty/parsers/test_default.rb +25 -21
- data/test/gravaty/parsers/test_force.rb +9 -1
- data/test/gravaty/parsers/test_format.rb +18 -11
- data/test/gravaty/parsers/test_pixelsize.rb +19 -12
- data/test/gravaty/parsers/test_rating.rb +18 -11
- data/test/gravaty/parsers/test_secure.rb +9 -1
- data/test/gravaty/parsers/test_type.rb +14 -5
- data/test/gravaty/test_application.rb +14 -6
- data/test/gravaty/test_avatar.rb +94 -59
- data/test/gravaty/test_parser.rb +11 -5
- data/test/gravaty/test_profile.rb +47 -25
- data/test/gravaty/utils/test_downloader.rb +43 -28
- data/test/gravaty/utils/test_raisers.rb +42 -26
- data/test/gravaty/utils/test_rfc5322.rb +35 -13
- data/test/gravaty/utils/test_rpc_connector.rb +83 -39
- data/test/test_gravaty.rb +12 -4
- data/test/test_helper.rb +15 -9
- metadata +54 -40
- data/ISSUES.md +0 -62
- data/acknowledgements.md +0 -66
- data/authors.md +0 -63
- data/examples/cacert.pem +0 -3466
- data/html/ISSUES_md.html +0 -166
- data/html/acknowledgements_md.html +0 -161
- data/html/authors_md.html +0 -174
- 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
|
-
#
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
data/lib/gravaty/application.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
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
|
-
|
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
|
-
[
|
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
|
133
|
-
|
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
|
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
|
-
|
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
|
197
|
-
|
207
|
+
if filename.nil?
|
208
|
+
filename = URI.parse(@gravaty).path.rpartition('/')
|
209
|
+
.last
|
210
|
+
end
|
198
211
|
Utils::Downloader::Downloader
|
199
|
-
|
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
|
296
|
-
|
297
|
-
|
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 =
|
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 <=>(
|
326
|
-
@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
|
-
|
354
|
+
.join('&')
|
340
355
|
end
|
341
356
|
|
342
|
-
return
|
343
|
-
|
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
|
349
|
-
@parser.parse('secure', secure)
|
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
|
data/lib/gravaty/constants.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
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 = [
|
29
|
-
|
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
|
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
|
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
|
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
|
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
|
57
|
+
PROFILES = %w[json qr].freeze
|
50
58
|
|
51
59
|
# Allowed rating options. Currently: g, pg, r and x.
|
52
|
-
RATING_OPTIONS = %w
|
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
|
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'
|
data/lib/gravaty/locales/en.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
#--
|
1
2
|
# gravaty
|
2
|
-
#
|
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
|
data/lib/gravaty/locales/it.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
#--
|
1
2
|
# gravaty
|
2
|
-
#
|
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
|
data/lib/gravaty/locales/ja.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
#--
|
1
2
|
# gravaty
|
2
|
-
#
|
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 を使用
|
data/lib/gravaty/parser.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# gravaty
|
3
|
-
#
|
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 =
|
36
|
-
ALLOWED_PARAMS.each
|
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,
|
49
|
+
def parse(method = nil, params = nil)
|
43
50
|
a_parser = nil
|
44
|
-
a_parser = parsers[method.to_sym] unless method.nil?
|
45
|
-
|
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
|