utt/lib/seg.rb

32 lines
343 B
Ruby
Raw Normal View History

class Seg
def initialize(s="")
@line=s
self
end
def to_s
@line.chomp
end
def set(s)
@line=s
self
end
def field(key)
if key.class==Fixnum
@line.split[key-1]
elsif key.class==String
@line =~ /\s#{key}:(\S+)/; $1
end
end
alias [] field
def fields
@line.split
end
end