Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Created August 24, 2012 21:49
Show Gist options
  • Save kwilczynski/3456045 to your computer and use it in GitHub Desktop.
Save kwilczynski/3456045 to your computer and use it in GitHub Desktop.
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:~$
#!/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
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