X
x1
Is it possible to sort the jobs hash below based on values such as
command, start_time and stop_time?
Ideally, sort_by would be dynamically provided and I would output the
jobs entries based on the value defined for sort_by.
--------------------------(basic_script.rb)------------------------
sort_by =3D "start_time" #<---- I'd like to use something like this to
define which job is listed first
jobs =3D {
=09=09"2231" =3D> {"command" =3D> "test_a.bash",
=09=09=09=09"start_time" =3D> "20051211",
=09=09=09=09"stop_time" =3D> "20051222"},
=09=09"1131" =3D> {"command" =3D> "test_b.bash",
=09=09=09=09"start_time" =3D> "20051011",
=09=09=09=09"stop_time" =3D> "20051122"},
=09=09"231" =3D> {"command" =3D> "test_c.bash",
=09=09=09=09"start_time" =3D> "20051215",
=09=09=09=09"stop_time" =3D> "20051227"}
=09}
jobs.each do |job, attributes|
puts "------------------"
=09puts attributes["command"]
=09puts attributes["start_time"]
=09puts attributes["stop_time"]
end
--------------------------(/basic_script.rb)------------------------
This is the default output:
./basic_script.rb
------------------
test_c.bash
20051215
20051227
------------------
test_b.bash
20051011
20051122
------------------
test_a.bash
20051211
20051222
Id like to have the dynamics of say, ordering these by attribute such
as start_time:
(I wish I could get this)
test_b.bash
20051011
20051122
------------------
test_a.bash
20051211
20051222
------------------
test_c.bash
20051215
20051227
Any suggestions?
thanks in advance.
command, start_time and stop_time?
Ideally, sort_by would be dynamically provided and I would output the
jobs entries based on the value defined for sort_by.
--------------------------(basic_script.rb)------------------------
sort_by =3D "start_time" #<---- I'd like to use something like this to
define which job is listed first
jobs =3D {
=09=09"2231" =3D> {"command" =3D> "test_a.bash",
=09=09=09=09"start_time" =3D> "20051211",
=09=09=09=09"stop_time" =3D> "20051222"},
=09=09"1131" =3D> {"command" =3D> "test_b.bash",
=09=09=09=09"start_time" =3D> "20051011",
=09=09=09=09"stop_time" =3D> "20051122"},
=09=09"231" =3D> {"command" =3D> "test_c.bash",
=09=09=09=09"start_time" =3D> "20051215",
=09=09=09=09"stop_time" =3D> "20051227"}
=09}
jobs.each do |job, attributes|
puts "------------------"
=09puts attributes["command"]
=09puts attributes["start_time"]
=09puts attributes["stop_time"]
end
--------------------------(/basic_script.rb)------------------------
This is the default output:
./basic_script.rb
------------------
test_c.bash
20051215
20051227
------------------
test_b.bash
20051011
20051122
------------------
test_a.bash
20051211
20051222
Id like to have the dynamics of say, ordering these by attribute such
as start_time:
(I wish I could get this)
test_b.bash
20051011
20051122
------------------
test_a.bash
20051211
20051222
------------------
test_c.bash
20051215
20051227
Any suggestions?
thanks in advance.