Class: Zizia::BasedNearAttributes
- Inherits:
-
Object
- Object
- Zizia::BasedNearAttributes
- Defined in:
- lib/zizia/hyrax/based_near_attributes.rb
Instance Attribute Summary collapse
-
#based_near ⇒ Object
Returns the value of attribute based_near.
Instance Method Summary collapse
-
#initialize(based_near) ⇒ BasedNearAttributes
constructor
A new instance of BasedNearAttributes.
-
#to_h ⇒ Hash
When submitting location data (a.k.a. the “based near” attribute) via the UI, Hyrax expects to receive a ‘based_near_attributes` hash in a specific format.
-
#uri_to_sws(uri) ⇒ String
Take a user-facing geonames URI and return an sws URI, of the form Hyrax expects (e.g., “sws.geonames.org/6252001/”).
Constructor Details
#initialize(based_near) ⇒ BasedNearAttributes
Returns a new instance of BasedNearAttributes.
7 8 9 |
# File 'lib/zizia/hyrax/based_near_attributes.rb', line 7 def initialize(based_near) @based_near = based_near end |
Instance Attribute Details
#based_near ⇒ Object
Returns the value of attribute based_near.
5 6 7 |
# File 'lib/zizia/hyrax/based_near_attributes.rb', line 5 def based_near @based_near end |
Instance Method Details
#to_h ⇒ Hash
When submitting location data (a.k.a. the “based near” attribute) via the UI, Hyrax expects to receive a ‘based_near_attributes` hash in a specific format. We need to take geonames urls as provided by the customer and transform them to mimic what the Hyrax UI would ordinarily produce. These will get turned into Hyrax::ControlledVocabularies::Location objects upon ingest. The expected hash looks like this:
"based_near_attributes"=>
{
"0"=> {
"id"=>"http://sws.geonames.org/5667009/", "_destroy"=>""
},
"1"=> {
"id"=>"http://sws.geonames.org/6252001/", "_destroy"=>""
},
}
28 29 30 31 32 33 34 35 36 |
# File 'lib/zizia/hyrax/based_near_attributes.rb', line 28 def to_h original_geonames_uris = based_near return if original_geonames_uris.empty? based_near_attributes = {} original_geonames_uris.each_with_index do |uri, i| based_near_attributes[i.to_s] = { 'id' => uri_to_sws(uri), "_destroy" => "" } end based_near_attributes end |
#uri_to_sws(uri) ⇒ String
Take a user-facing geonames URI and return an sws URI, of the form Hyrax expects (e.g., “sws.geonames.org/6252001/”)
43 44 45 46 47 |
# File 'lib/zizia/hyrax/based_near_attributes.rb', line 43 def uri_to_sws(uri) uri = URI(uri) geonames_number = uri.path.split('/')[1] "http://sws.geonames.org/#{geonames_number}/" end |