Sha256: 2e25ce8ec10bc8daf22477f44e9494c10a185936767013994e864114ad924aa2

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module OData
  # Helper methods
  class Helpers
    # Helper to normalize the results of a select result; Ruby 1.9 Hash.select returns a Hash, 1.8 returns an Array
    # This is for Ruby 1.8 support, but should be removed in the future
    def self.normalize_to_hash(val)
      return nil if val.nil?
      (val.is_a? Hash) ? val : Hash[*val.flatten]
    end

    # Wrapper for URI escaping that switches between URI::Parser#escape and
    # URI.escape for 1.9-compatibility (thanks FakeWeb https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/utility.rb#L40)
    def self.uri_escape(*args)
      if URI.const_defined?(:Parser)
        URI::Parser.new.escape(*args)
      else
        URI.escape(*args)
      end
    end

    # Nokogiri changed how it handles namespaced attributes with v1.5.1, this is for backwards compatibility to >= 1.4.2
    # Nokogiri now >=1.5.1 requires the namespace prefix is used
    def self.get_namespaced_attribute(node, attr_name, prefix)
      return node["#{prefix}:#{attr_name}"] || node[attr_name]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby_odata-0.2.0.beta1 lib/ruby_odata/helpers.rb
ruby_odata-0.1.6 lib/ruby_odata/helpers.rb
ruby_odata-0.1.5 lib/ruby_odata/helpers.rb
ruby_odata-0.1.4 lib/ruby_odata/helpers.rb
ruby_odata-0.1.3 lib/ruby_odata/helpers.rb
ruby_odata-0.1.2 lib/ruby_odata/helpers.rb