Class: SC::Helpers::EntrySorter
- Inherits:
-
Object
- Object
- SC::Helpers::EntrySorter
- Defined in:
- lib/sproutcore/helpers/entry_sorter.rb
Overview
Sorts a set of entries, respecting any "requires" found in the entries. To use the sorter, just call the class method EntrySorter.sort() passing the entries to sort along with any filenames you prefer to have added to the top. If you don't specify any filenames, then the entries will be sorted alphabetically except for requires.
Instance Attribute Summary collapse
-
#preferred_filenames ⇒ Object
readonly
Returns the value of attribute preferred_filenames.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(preferred_filenames = []) ⇒ EntrySorter
constructor
A new instance of EntrySorter.
- #sort(entries) ⇒ Object
Constructor Details
#initialize(preferred_filenames = []) ⇒ EntrySorter
23 24 25 |
# File 'lib/sproutcore/helpers/entry_sorter.rb', line 23 def initialize(preferred_filenames = []) @preferred_filenames = preferred_filenames end |
Instance Attribute Details
#preferred_filenames ⇒ Object (readonly)
Returns the value of attribute preferred_filenames.
27 28 29 |
# File 'lib/sproutcore/helpers/entry_sorter.rb', line 27 def preferred_filenames @preferred_filenames end |
Class Method Details
.sort(entries, preferred_filenames = []) ⇒ Object
19 20 21 |
# File 'lib/sproutcore/helpers/entry_sorter.rb', line 19 def self.sort(entries, preferred_filenames = []) self.new(preferred_filenames).sort(entries) end |
Instance Method Details
#sort(entries) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sproutcore/helpers/entry_sorter.rb', line 29 def sort(entries) # first sort entries by filename - ignoring case entries = entries.sort do |a,b| (a.filename || '').to_s.downcase <=> (b.filename || '').to_s.downcase end all_entries = entries.dup # needed for sort... # now process each entry to handle requires seen = [] ret = [] while cur = next_entry(entries) add_entry_to_set(cur, ret, seen, entries, all_entries) end return ret end |