Created
August 7, 2014 19:45
-
-
Save rebeccaskinner/d7268f23b7c848365f91 to your computer and use it in GitHub Desktop.
Field-separated value parser
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
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