Skip to content

Instantly share code, notes, and snippets.

@rebeccaskinner
Created August 7, 2014 19:45
Show Gist options
  • Save rebeccaskinner/d7268f23b7c848365f91 to your computer and use it in GitHub Desktop.
Save rebeccaskinner/d7268f23b7c848365f91 to your computer and use it in GitHub Desktop.
Field-separated value parser
module DynamicNetworkGraph
class NetworkFlow
Fields = [:srcAddr,:dstAddr,:srcPort,:dstPort,:protocol,:start,:end,:packets,:transferred,:status]
attr_accessor :srcAddr
attr_accessor :dstAddr
attr_accessor :srcPort
attr_accessor :dstPort
attr_accessor :protocol
attr_accessor :start
attr_accessor :end
attr_accessor :packets
attr_accessor :transferred
attr_accessor :status
def fromFields(sep,line)
def symToAssignment(symVal)
"#{symVal}=".to_sym
end
line.split(sep).zip(Fields.map {|x| symToAssignment(x)}).map do |(fieldVal,fieldName)|
self.method(fieldName).call(fieldVal)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment