Sha256: 4735c7f5d70a7e38f0915bf1a203f28cd7221e98c9c71450bad01768bddc891b
Contents?: true
Size: 915 Bytes
Versions: 6
Compression:
Stored size: 915 Bytes
Contents
# -*- encoding: utf-8 -*- # frozen_string_literal: true module RDF class Node # Odd case of appending to a BNode identifier def +(value) Node.new(id + value.to_s) 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 = %w(@base @id @value @type @language @vocab @container @graph @list @set @index).freeze # Order, considering keywords to come before other strings 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 # Order terms, length first, then lexographically def term_sort self.sort do |a, b| len_diff = a.length <=> b.length len_diff == 0 ? a <=> b : len_diff end end end
Version data entries
6 entries across 6 versions & 1 rubygems