101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/crm_formatter/web.rb', line 101
def validate_extension(url_hash, url)
return unless url.present?
uri_parts = URI(url).host&.split('.')
url_exts = uri_parts[2..-1]
if url_exts.empty?
err_msg = 'error: ext.none'
else
iana_list = CrmFormatter::Extensions.list
matched_exts = iana_list & url_exts
if matched_exts.empty?
err_msg = "error: ext.invalid [#{url_exts.join(', ')}]"
elsif matched_exts.count > 1
err_msg = "error: ext.valid > 1 [#{matched_exts.join(', ')}]"
end
end
if err_msg
url_hash[:web_neg] << err_msg
url = nil
url_hash[:url_f] = nil
return { url_hash: url_hash, url: url }
end
if url_exts.count > matched_exts.count
matched_ext = matched_exts.first
u1 = url.split(matched_ext).first
url = "#{u1}#{matched_ext}"
end
ext_result = { url_hash: url_hash, url: url }
ext_result
end
|