Skip to content

Commit 347d94a

Browse files
committed
De-duplicate providers in case where e.g. content provider and host institution are the same org. Hide empty string address fields
1 parent 542de22 commit 347d94a

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

lib/bioschemas/generator.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def self.address(event)
9696
'addressRegion' => event.county,
9797
'addressCountry' => event.country,
9898
'postalCode' => event.postcode
99-
}.compact,
99+
}.compact_blank,
100100
'latitude' => event.latitude,
101101
'longitude' => event.longitude
102-
}.compact
102+
}.compact_blank
103103
end
104104

105105
# Reverse the process used by TeSS_RDF_Extractors to turn a list of values into a markdown list.
@@ -137,15 +137,6 @@ def self.external_resources(resource)
137137
def self.provider(resource)
138138
p = []
139139

140-
if resource.respond_to?(:host_institutions)
141-
resource.host_institutions.each do |i|
142-
p << {
143-
'@type' => 'Organization',
144-
'name' => i
145-
}
146-
end
147-
end
148-
149140
if resource.content_provider
150141
p << {
151142
'@type' => 'Organization',
@@ -162,6 +153,17 @@ def self.provider(resource)
162153
}
163154
end
164155

156+
if resource.respond_to?(:host_institutions)
157+
resource.host_institutions.each do |i|
158+
p << {
159+
'@type' => 'Organization',
160+
'name' => i
161+
}
162+
end
163+
end
164+
165+
p.uniq! { |o| o['name'].downcase.strip }
166+
165167
p.any? ? p : nil
166168
end
167169
end

test/models/event_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,4 +757,22 @@ class EventTest < ActiveSupport::TestCase
757757
refute event.valid?
758758
assert event.errors.added?(:keywords, :too_long, count: 20)
759759
end
760+
761+
test 'blank address fields are removed from event bioschemas json' do
762+
e = Event.new(city: 'Manchester', country: '', event_types: ['workshops_and_courses'])
763+
bioschemas = e.to_bioschemas.first.generate
764+
address = bioschemas[:hasCourseInstance].first[:location]['address']
765+
assert_equal 'Manchester', address['addressLocality']
766+
assert_equal ['@type', 'addressLocality'].sort, address.keys.sort
767+
end
768+
769+
test 'de-duplicates provider in event bioschemas json' do
770+
e = Event.new(content_provider: content_providers(:goblet), host_institutions: 'Goblet',
771+
event_types: ['workshops_and_courses'])
772+
773+
bioschemas = e.to_bioschemas.first.generate
774+
assert_equal 1, bioschemas[:provider].length
775+
assert_equal 'Goblet', bioschemas[:provider].first['name']
776+
assert_equal 'http://mygoblet.org', bioschemas[:provider].first['url']
777+
end
760778
end

0 commit comments

Comments
 (0)