I suggest breaking down the tasks into methods for their respective responsibilities. You have here loading, filtering, and transforming. The methods could reflect that. (I haven't tested this code, but this should show the general idea.)
I think you'd be better off with something like this:
require "csv"
def load_alarms
CSV.read 'alarms.csv', {col_sep: ';'}
end
def filter_by_event_type_and_severity(alarms, event_type, severity)
alarms.select do |alarm|
alarm[1] == event_type && alarm[2].to_i == severity.to_i
end
end
target_alarms = filter_by_event_type_and_severity(
load_alarms, 'high', 1)
equipments = target_alarms.map { |alarm| alarm[0] }
descriptions = target_alarms.map { |alarm| alarm[3] }
p target_alarms
p equipments
p descriptions
Even if the implementations of the methods are trivially simple, this will give you the practice of separating code into logical parts, each of which is highly cohesive or specialized, with minimal coupling (dependency) on other parts of the code.
One of the biggest mistakes of beginners is trying to do too much in the same chunk of code -- high and low level code, and with totally unrelated subjects. Learning how to break problems down into smaller problems, and logically organizing them, is one of the important skills you can learn.
By the way, I don't recommend the to_i call on severity. Since the parameter is logically a number, you shouldn't really permit a string, IMO.
equipment.push(level[10]). And these should be outside theselect, I think.level[10]andlevel[13]? What did you mean by that? You only have 4 columns.