I am trying to write a script that will fill out a mapping of equipment by using if
statments on a text file.
Here is the code I have tried:
input.txt:
SWITCH
ROUTER
FIREWALL
ROUTER
ROUTER
FIREWALL
SWITCH
SWITCH
Ruby code:
IO.foreach("input.txt") do |type_equipment|
if type_equipment = "SWITCH"
puts "SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch"
elsif type_equipment = "ROUTER"
puts "ROUTER,BMC_COMPUTERSYSTEM,Network,Router,Ethernet Router"
elsif type_equipment = "FIREWALL"
puts "FIREWALL,BMC_COMPUTERSYSTEM,Network,Appliance,Firewall"
end
end
The code runs but it is outputting this:
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
SWITCH,BMC_COMPUTERSYSTEM,Network,Switch,Ethernet Switch
main.rb:6: warning: found = in conditional, should be ==
main.rb:4: warning: found = in conditional, should be ==
main.rb:2: warning: found = in conditional, should be ==
I want it to evaluate each line in the file and if it matches an if
statement, then output the associated puts
.
I have also tied the ==
for the if
statements but it only displays the result for the first line only with no warnings.