Module: Celsius::Primo::SoapApi::Searcher::SearchBrief::SearchResultTransformation::OxHelpers

Defined in:
lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation.rb

Class Method Summary collapse

Class Method Details

.hash_from_ox_element(ox_element) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation.rb', line 33

def self.hash_from_ox_element(ox_element)
  if string_element?(ox_element)
    ox_element.first.force_encoding("utf-8")
  else
    ox_element.nodes.inject({}) do |hash, node|
      key = node.value

      if hash[key].is_a?(String)
        hash[key] = [hash[key]]
      end

      if hash[key].is_a?(Array)
        hash[key] << hash_from_ox_element(node.nodes)
      else
        hash[key] = hash_from_ox_element(node.nodes)
      end

      hash
    end
  end
end

.string_element?(ox_element) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation.rb', line 55

def self.string_element?(ox_element)
  ox_element.is_a?(Array) && ox_element.length == 1 && ox_element.first.is_a?(String)
end