Skip to content

Commit

Permalink
make the map_attributes handle the option showing all the languages
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 14, 2023
1 parent 5952f87 commit a81f12c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/goo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ def self.range_object(attr,id)



def self.map_attributes(inst,equivalent_predicates=nil)
def self.map_attributes(inst,equivalent_predicates=nil, include_languages: false)
if (inst.kind_of?(Goo::Base::Resource) && inst.unmapped.nil?) ||
(!inst.respond_to?(:unmapped) && inst[:unmapped].nil?)
raise ArgumentError, "Resource.map_attributes only works for :unmapped instances"
end
klass = inst.respond_to?(:klass) ? inst[:klass] : inst.class
unmapped = inst.respond_to?(:klass) ? inst[:unmapped] : inst.unmapped
unmapped = inst.respond_to?(:klass) ? inst[:unmapped] : inst.unmapped(include_languages: include_languages)
list_attrs = klass.attributes(:list)
unmapped_string_keys = Hash.new
unmapped.each do |k,v|
Expand Down Expand Up @@ -398,13 +398,18 @@ def self.map_attributes(inst,equivalent_predicates=nil)
object = unmapped_string_keys[attr_uri]
end

object = object.map {|o| o.is_a?(RDF::URI) ? o : o.object}
if object.is_a?(Hash)
object = object.transform_values{|values| Array(values).map{|o|o.is_a?(RDF::URI) ? o : o.object}}
else
object = object.map {|o| o.is_a?(RDF::URI) ? o : o.object}
end

if klass.range(attr)
object = object.map { |o|
o.is_a?(RDF::URI) ? klass.range_object(attr,o) : o }
end
object = object.first unless list_attrs.include?(attr)

object = object.first unless list_attrs.include?(attr) || include_languages
if inst.respond_to?(:klass)
inst[attr] = object
else
Expand Down

0 comments on commit a81f12c

Please sign in to comment.