Class: Hx::Sort
Instance Method Summary collapse
- #each_entry(selector) ⇒ Object
- #edit_entry(path, prototype = nil) ⇒ Object
- #get_entry(path) ⇒ Object
-
#initialize(input, options) ⇒ Sort
constructor
A new instance of Sort.
Methods included from Filter
Constructor Details
Instance Method Details
#each_entry(selector) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/hx.rb', line 325 def each_entry(selector) entries = [] @input.each_entry(selector) do |path, entry| entries << [path, entry] end unless @key_fields.empty? entries = entries.sort_by do |path, entry| @key_fields.map { |f| entry[f] } end end entries.reverse! if @reverse entries.each do |path, entry| yield path, entry end self end |
#edit_entry(path, prototype = nil) ⇒ Object
320 321 322 323 |
# File 'lib/hx.rb', line 320 def edit_entry(path, prototype=nil) @input.edit_entry(path, prototype) { |text| yield text } self end |
#get_entry(path) ⇒ Object
342 343 344 |
# File 'lib/hx.rb', line 342 def get_entry(path) @input.get_entry(path) end |