Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/json/ld/extensions.rb
Constant Summary collapse
- KW_ORDER =
Sort values, but impose special keyword ordering
%w(@base @id @value @type @language @vocab @container @graph @list @set @index).freeze
Instance Method Summary collapse
-
#kw_sort ⇒ Object
Order, considering keywords to come before other strings.
-
#term_sort ⇒ Object
Order terms, length first, then lexographically.
Instance Method Details
#kw_sort ⇒ Object
Order, considering keywords to come before other strings
53 54 55 56 57 58 59 |
# File 'lib/json/ld/extensions.rb', line 53 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 |
#term_sort ⇒ Object
Order terms, length first, then lexographically
62 63 64 65 66 67 |
# File 'lib/json/ld/extensions.rb', line 62 def term_sort self.sort do |a, b| len_diff = a.length <=> b.length len_diff == 0 ? a <=> b : len_diff end end |