Skip to content

Commit

Permalink
Output facebook, twitter and instagram as URL
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Feb 28, 2024
1 parent 8648cc4 commit 31bdbbe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 6 additions & 3 deletions datasources/schemas/tags/base.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions datasources/transforms/osm_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def process_tags(tags)
[k, @multiple.include?(k) ? v.split(';').collect(&:strip) : v]
}.select{ |k, _v| !k.nil? }.to_h

@@url_format.each{ |key, formatter|
if tags.include?(key) && !tags[key].start_with?('http')
tags[key] = formatter.gsub('$1', tags[key])
end
}

(@@names + %i[addr ref description source]).each{ |key|
value = tags.delete(key)
tags = group(key, tags)
Expand Down Expand Up @@ -174,4 +180,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
11 changes: 8 additions & 3 deletions tests/osm_tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 31bdbbe

Please sign in to comment.