Class: Jekyll::AwesomeNav::SortOptions
- Inherits:
-
Object
- Object
- Jekyll::AwesomeNav::SortOptions
- 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
-
#initialize(value) ⇒ SortOptions
constructor
A new instance of SortOptions.
- #sort(items) ⇒ Object
Constructor Details
#initialize(value) ⇒ SortOptions
Returns a new instance of SortOptions.
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 |