lib/liquid/drops/concepts_drop.rb in metanorma-plugin-glossarist-0.1.2 vs lib/liquid/drops/concepts_drop.rb in metanorma-plugin-glossarist-0.1.3

- old
+ new

@@ -32,10 +32,11 @@ def filtered_concepts(concepts_collection, filters) concept_filters = filters.dup language_filter = concept_filters.delete('lang') sort_filter = concept_filters.delete('sort_by') + group_filter = concept_filters.delete('group') concepts = concepts_collection.to_h["managed_concepts"].map do |concept| filtered_concept = concept.dup filtered_concept.each do |field, concept_hash| next if NON_LANGUAGE_FIELDS.include?(field) @@ -59,16 +60,27 @@ else filtered_concept end end.compact + apply_group_filter(concepts, group_filter) apply_sort_filter(concepts, sort_filter) end def apply_sort_filter(concepts, sort_by) return concepts unless sort_by concepts.sort_by { |concept| concept.dig(*extract_nested_field_names(sort_by)) } + end + + def apply_group_filter(concepts, groups) + return concepts unless groups + + concepts.select! do |concept| + groups.split(",").reduce(true) do |pre_result, group| + pre_result && concept["groups"].include?(group.strip) + end + end end def extract_nested_field_names(name) name.split(".").map do |field| field_name = field.strip