-
-
Save kwilczynski/3456045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
krzysztof@samsung:~$ ruby test.rb test.csv 10.39.30.252 | |
"S2774" | |
krzysztof@samsung:~$ ruby test.rb test.csv 10.39.30.255 | |
:unknown | |
krzysztof@samsung:~$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'csv' | |
class Location | |
attr_reader :file | |
def initialize(file) | |
@file = file | |
@data = Hash.new do |h,k| | |
h[k] = { :location => :unknown, :device_type => :unknown } | |
end | |
CSV.read(file).each do |line| | |
@data[line.shift] = { :location => line.shift, | |
:device_type => line.shift } | |
end | |
end | |
def get_location(location) | |
@data[location][:location] | |
end | |
end | |
if $0 == __FILE__ | |
file, location = ARGV.shift, ARGV.shift | |
l = Location.new(file) | |
p l.get_location(location) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10.39.30.251 | S2774 | RFS | |
---|---|---|---|
10.39.30.252 | S2774 | RFS | |
10.39.67.251 | S2933 | RFS | |
10.39.67.252 | S2933 | RFS | |
10.39.71.251 | S2945 | RFS | |
10.39.71.252 | S2945 | RFS | |
10.39.8.251 | S2664 | RFS | |
10.39.8.252 | S2664 | RFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment