Class: Yaml::Sort::List
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(dash, value) ⇒ Object
-
#initialize(items = []) ⇒ List
constructor
A new instance of List.
- #sort ⇒ Object
- #to_s ⇒ Object
Methods inherited from Value
Constructor Details
#initialize(items = []) ⇒ List
Returns a new instance of List.
8 9 10 11 |
# File 'lib/yaml/sort/list.rb', line 8 def initialize(items = []) super() @items = items end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/yaml/sort/list.rb', line 6 def items @items end |
Class Method Details
Instance Method Details
#add_item(dash, value) ⇒ Object
13 14 15 |
# File 'lib/yaml/sort/list.rb', line 13 def add_item(dash, value) @items << [dash, value] end |
#sort ⇒ Object
29 30 31 32 |
# File 'lib/yaml/sort/list.rb', line 29 def sort # TODO: Add an option to sort scalar values List.new(items.map { |i| [i[0], i[1].sort] }) end |
#to_s ⇒ Object
23 24 25 26 27 |
# File 'lib/yaml/sort/list.rb', line 23 def to_s super + items.map do |item| "#{item[0]}#{item[1].to_s(skip_first_indent: true)}" end.join("\n") end |