/*
 * ServerAnswer.j
 * RouteIntelligence
 *
 * Created by P. Miranda on June 29, 2010.
 * Copyright 2010, Predisoft Internacional S.A. All rights reserved.
 */



@import <Foundation/CPObject.j>
@import "ServerRecord.j"

 

@implementation ServerAnswer : CPObject {
    id          recs;
	id          titl;
}




- (int) count {
   return [recs count];
}


- (id) initWithAnswer:(CPString)_answ {
	[super init];
	var sepa = @"|$@!$|";
	if ( recs )
	     [recs release];
	recs = [[CPMutableArray alloc] init];
	var arra = [_answ componentsSeparatedByString:sepa];
	
	if ( [arra count] == 1 ) {
	     [recs addObject:_answ];
		 titl = [[CPArray alloc] init];
		 return self;
		 }
		 
	var line = [arra objectAtIndex:0];	
	titl = [[CPArray alloc] initWithArray:[line componentsSeparatedByString:@"|"]];
	var i;
	for ( i=1;i<[arra count];i++) {
	      var arro = [[arra objectAtIndex:i] componentsSeparatedByString:@"|&*&|"];
		  if (arro) {
		      var sr = [[ServerRecord alloc] initWithKeyList:titl valueList:arro];
			  [recs addObject:sr];
		  }
		}
	return self;
}



- (id) objectAtIndex:(int)inde {
	return [recs objectAtIndex:inde];
}

- (CPArray) elements {
	return recs;
}


@end