Class: Jekyll::AwesomeNav::SortOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/awesome_nav/sort_options.rb

Constant Summary collapse

DEFAULTS =
{
  "direction" => "asc",
  "type" => "alphabetical",
  "by" => "path",
  "sections" => "first",
  "ignore_case" => true
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ SortOptions

Returns a new instance of SortOptions.

Raises:



18
19
20
21
22
# File 'lib/jekyll/awesome_nav/sort_options.rb', line 18

def initialize(value)
  raise Error, "sort must be a mapping" unless value.nil? || value.is_a?(Hash)

  @data = DEFAULTS.merge(value || {})
end

Class Method Details

.from(value) ⇒ Object



14
15
16
# File 'lib/jekyll/awesome_nav/sort_options.rb', line 14

def self.from(value)
  new(value)
end

Instance Method Details

#sort(items) ⇒ Object



24
25
26
27
# File 'lib/jekyll/awesome_nav/sort_options.rb', line 24

def sort(items)
  sorted = Array(items).sort_by { |item| sort_key(item) }
  direction == "desc" ? sorted.reverse : sorted
end