Method: Cloudlib::Entry#set_attribute

Defined in:
lib/cloudlib.rb

#set_attribute(attribute, ans) ⇒ Object

Sets the specified metadata attribute to ans. ans is assumed to be a regular string. It will be split by “ and ” for authors and editors, or by spaces for keywords.



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/cloudlib.rb', line 305

def set_attribute(attribute, ans)
  index = ['title', 'authors', 'editors', 'booktitle'].member?(attribute)
  if ans.nil? || ans.empty?
    self.attributes[attribute] = nil
  else
    newval = if attribute == 'editors' || attribute == 'authors'
                ans.split(" and ").map {|a| a.strip}
             elsif attribute == 'keywords'
                ans.split
             else
                [ans.strip]
             end
    self.attributes[attribute] = newval
    unless ['url', 'doi', 'keywords'].member?(attribute)
      self.attributes[attribute + "_lowercase"] = newval.map {|a| a.downcase}
      self.attributes[attribute + "_words"] = self.attributes[attribute + "_lowercase"].map {|a| a.split(/[[:punct:]]*[[:space:]]+|-+/)}.flatten.reject {|a| a.empty?}
    end
    # recalculate all_words
    tit_auth_words = ['title', 'authors', 'editors', 'booktitle'].map {|att| self.attributes[att + "_words"] || []}.flatten
    keywords = self.attributes['keywords'] || []
    self.attributes['all_words'] = keywords + tit_auth_words
  end
end