32 lines
343 B
Ruby
32 lines
343 B
Ruby
|
|
||
|
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
|