diff --git a/datasources/schemas/tags/base.schema.json b/datasources/schemas/tags/base.schema.json index 7055904..82a4d4a 100644 --- a/datasources/schemas/tags/base.schema.json +++ b/datasources/schemas/tags/base.schema.json @@ -52,13 +52,16 @@ } }, "facebook": { - "type": "string" + "type": "string", + "format": "uri" }, "twitter": { - "type": "string" + "type": "string", + "format": "uri" }, "instagram": { - "type": "string" + "type": "string", + "format": "uri" }, "contact:linkedin": { "type": "string" diff --git a/datasources/transforms/osm_tags.rb b/datasources/transforms/osm_tags.rb index 839b873..76197da 100755 --- a/datasources/transforms/osm_tags.rb +++ b/datasources/transforms/osm_tags.rb @@ -63,6 +63,15 @@ def remove_contact_prefix(tags, key, has_flat_addr) end end + def tags_to_url(tags) + @@url_format.each{ |key, formatter| + if tags.include?(key) && !tags[key].start_with?('http') + tags[key] = formatter.gsub('$1', tags[key]) + end + } + tags + end + def process_tags(tags) # There is an adresse defined by addr:* ? has_flat_addr = tags.keys.find{ |k| k.start_with?('addr:') } @@ -75,6 +84,8 @@ def process_tags(tags) [k, @multiple.include?(k) ? v.split(';').collect(&:strip) : v] }.select{ |k, _v| !k.nil? }.to_h + tags = tags_to_url(tags) + (@@names + %i[addr ref description source]).each{ |key| value = tags.delete(key) tags = group(key, tags) @@ -174,4 +185,10 @@ def process_data(row) quarter block_number ] + + @@url_format = { + facebook: 'https://www.facebook.com/$1', + twitter: 'https://twitter.com/$1', + instagram: 'https://www.instagram.com/$1', + } end diff --git a/tests/osm_tags_test.rb b/tests/osm_tags_test.rb index f492ee2..0efab65 100644 --- a/tests/osm_tags_test.rb +++ b/tests/osm_tags_test.rb @@ -19,9 +19,9 @@ def test_split end def test_contact_social - assert_equal({ facebook: 'a' }, map({ facebook: 'a' })) - assert_equal({ facebook: 'b' }, map({ 'contact:facebook': 'b' })) - assert_equal({ facebook: 'a' }, map({ facebook: 'a', 'contact:facebook': 'b' })) + assert_equal({ facebook: 'https://www.facebook.com/a' }, map({ facebook: 'a' })) + assert_equal({ facebook: 'https://www.facebook.com/b' }, map({ 'contact:facebook': 'b' })) + assert_equal({ facebook: 'https://www.facebook.com/a' }, map({ facebook: 'a', 'contact:facebook': 'b' })) end def test_contact_addr @@ -40,4 +40,9 @@ def test_default_name assert_equal({ name: { 'fr' => 'a' }, alt_name: { 'fr' => 'a' } }, map({ 'alt_name' => 'a' })) assert_equal({ name: { 'fr' => 'a', 'de' => 'b' }, alt_name: { 'de' => 'b' } }, map({ 'name:fr' => 'a', 'alt_name:de' => 'b' })) end + + def test_url_formatter + assert_equal({ facebook: 'https://www.facebook.com/a' }, map({ 'facebook' => 'a' })) + assert_equal({ facebook: 'https://face.book' }, map({ 'facebook' => 'https://face.book' })) + end end