Class: YAMLCommand::Command::SortCommand
- Inherits:
-
YAMLCommand::Command
- Object
- Executable::Command
- YAMLCommand::Command
- YAMLCommand::Command::SortCommand
- Defined in:
- lib/yaml_command/sort.rb
Overview
Sort command.
Very limited at this point as it will only sort toplevel sequence or mappings.
Instance Attribute Summary collapse
-
#order ⇒ Object
Select ordering, descending or ascending (default).
Attributes inherited from YAMLCommand::Command
Instance Method Summary collapse
-
#call(ypath = nil) ⇒ Object
Sort in ascending or descending order.
Methods inherited from YAMLCommand::Command
command_name, #debug=, #debug?, #h!, #help!, #inspect=, #inspect?, #json=, #json?, #mute=, #mute?, #yaml=, #yaml?
Instance Attribute Details
#order ⇒ Object
Select ordering, descending or ascending (default). Use descending or reverse or abbreviations d or r for opposite order.
16 17 18 |
# File 'lib/yaml_command/sort.rb', line 16 def order @order end |
Instance Method Details
#call(ypath = nil) ⇒ Object
Sort in ascending or descending order.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/yaml_command/sort.rb', line 20 def call(ypath=nil) if ypath raise NotImplementedError, "YPath not supported yet." end case data when Array new_data = data.sort when Hash new_data = {} data.keys.sort.each do |k| new_data[k] = data[k] end end #save output new_data end |