module Shibkit::MetaMeta::Mixin::XPathChores

A few simple utility functions for slurping data from XML

Private Instance Methods

extract_lang_map_of_objects(xpath, req_class) click to toggle source

Language-mapped Hash

# File lib/shibkit/meta_meta/mixin/xpath_chores.rb, line 83
def extract_lang_map_of_objects(xpath, req_class)
  
  results      = Hash.new
  results[:en] = Array.new
  
  @noko.xpath(xpath).each do |ix|
    
    case req_class.respond_to?(:filter)
    when true
      obj = req_class.new(ix).filter
    when false
      obj = req_class.new(ix)
    end
    
    if obj
      lang = ix['lang'] || :en
      results[lang] ||= Array.new
      results[lang] << obj
    end
    
  end
  
  return results
  
end
extract_lang_map_of_string_lists(xpath) click to toggle source

Language-mapped Hash of string lists

# File lib/shibkit/meta_meta/mixin/xpath_chores.rb, line 63
def extract_lang_map_of_string_lists(xpath)
  
  results      = Hash.new
  results[:en] = Array.new
  
  @noko.xpath(xpath).each do |ix|
  
    items = ix.content.split(' ')
    items.each { |item| item.gsub!('+',' ') }
    
    lang = ix['lang'] || :en
    results[lang.to_sym] = items

  end
  
  return results
  
end
extract_lang_map_of_strings(xpath) click to toggle source

Language-mapped Hash

# File lib/shibkit/meta_meta/mixin/xpath_chores.rb, line 45
def extract_lang_map_of_strings(xpath)
  
  results      = Hash.new
  results[:en] = Array.new
  

  @noko.xpath(xpath).each do |ix|

    lang = ix['lang'] || :en
    results[lang.to_sym] = ix.content.strip.squeeze('')

  end
  
  return results
  
end
extract_simple_list(xpath) click to toggle source

Return array of element contents when given xpath

# File lib/shibkit/meta_meta/mixin/xpath_chores.rb, line 30
def extract_simple_list(xpath)
  
  results = Array.new
  
  @noko.xpath(xpath).each do |ix|
    
    results << ix.content.to_s.strip
    
  end
  
  return results
  
end