Class: DataPackage::CreatorDeserializer
- Inherits:
-
BaseDeserializer
- Object
- BaseDeserializer
- DataPackage::CreatorDeserializer
- Defined in:
- app/deserializers/data_package/creator_deserializer.rb
Instance Method Summary collapse
Methods inherited from BaseDeserializer
Constructor Details
This class inherits a constructor from DataPackage::BaseDeserializer
Instance Method Details
#deserialize ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/deserializers/data_package/creator_deserializer.rb', line 3 def deserialize return unless @object && @object["roles"]&.include?("creator") attributes = { name: @object["title"], caption: @object["caption"], notes: @object["description"], links_attributes: [] } begin = Rails.application.routes.recognize_path(@object["path"]) if [:controller] == "creators" attributes[:id] = Creator.find_param([:id]).id end rescue ActiveRecord::RecordNotFound # ID wasn't found, match by name instead attributes[:id] = Creator.find_by(name: attributes[:name])&.id rescue ActionController::RoutingError # ID wasn't found, match by name instead attributes[:id] = Creator.find_by(name: attributes[:name])&.id attributes[:links_attributes] << {url: @object["path"]} if @object["path"]&.match?(URI::RFC2396_PARSER.make_regexp) end attributes[:links_attributes].concat(@object["links"]&.map { LinkDeserializer.new(it).deserialize } || []) attributes.compact_blank end |