lib/json/ld/extensions.rb in json-ld-0.3.2 vs lib/json/ld/extensions.rb in json-ld-0.9.0

- old
+ new

@@ -60,9 +60,27 @@ end end end end +class Array + # Sort values, but impose special keyword ordering + # @yield a, b + # @yieldparam [Object] a + # @yieldparam [Object] b + # @yieldreturn [Integer] + # @return [Array] + KW_ORDER = %(@id @value @type @language @vocab @container @graph @list @set) + + def kw_sort + self.sort do |a, b| + a = "@#{KW_ORDER.index(a)}" if KW_ORDER.include?(a) + b = "@#{KW_ORDER.index(b)}" if KW_ORDER.include?(b) + a <=> b + end + end +end + if RUBY_VERSION < "1.9" class InsertOrderPreservingHash < Hash include Enumerable def initialize(*args, &block) \ No newline at end of file