Skip to content

Commit

Permalink
Use Set consistently for collections of entities. #27
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Aug 31, 2022
1 parent b831345 commit c7b75c0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/ro_crate/model/crate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ def preview=(preview)
##
# All the entities within the crate. Includes contextual entities, data entities, the crate itself and its metadata file.
#
# @return [Array<Entity>]
# @return [Set<Entity>]
def entities
default_entities | data_entities.to_a | contextual_entities.to_a
default_entities | data_entities | contextual_entities
end

##
# Entities for the metadata file and crate itself, which should be present in all RO-Crates.
#
# @return [Array<Entity>]
# @return [Set<Entity>]
def default_entities
[metadata, preview, self]
Set.new([metadata, preview, self])
end

def properties
Expand Down Expand Up @@ -250,8 +250,7 @@ def payload
# Gather a map of entries, starting from the crate itself, then any directory data entities, then finally any
# file data entities. This ensures in the case of a conflict, the more "specific" data entities take priority.
entries = own_payload
non_self_entities = default_entities.reject { |e| e == self }
sorted_entities = (non_self_entities | data_entities.to_a).sort_by { |e| e.is_a?(ROCrate::Directory) ? 0 : 1 }
sorted_entities = (default_entities.delete(self) | data_entities).sort_by { |e| e.is_a?(ROCrate::Directory) ? 0 : 1 }

sorted_entities.each do |entity|
entity.payload.each do |path, entry|
Expand Down

0 comments on commit c7b75c0

Please sign in to comment.