Skip to content

Commit c3e6935

Browse files
committed
fixed error on Ruby 2.6
filter_map was added in 2.7
1 parent 5741b94 commit c3e6935

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/didkit/document.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@ def initialize(did, json)
2121
@did = did
2222
@json = json
2323

24-
if service = json['service']
25-
raise FormatError, "Invalid service data" unless service.is_a?(Array) && service.all? { |x| x.is_a?(Hash) }
24+
@services = parse_services(json['service'] || [])
25+
@handles = parse_also_known_as(json['alsoKnownAs'] || [])
26+
end
27+
28+
def parse_services(service_data)
29+
raise FormatError, "Invalid service data" unless service_data.is_a?(Array) && service_data.all? { |x| x.is_a?(Hash) }
2630

27-
@services = service.filter_map { |x|
28-
id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint')
29-
next unless id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String)
31+
services = []
3032

31-
ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint)
32-
}
33-
else
34-
@services = []
33+
service_data.each do |x|
34+
id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint')
35+
36+
if id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String)
37+
services << ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint)
38+
end
3539
end
3640

37-
@handles = parse_also_known_as(json['alsoKnownAs'] || [])
41+
services
3842
end
3943

4044
def get_verified_handle

0 commit comments

Comments
 (0)