Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: SimpleNumberStringParserFactory. #19

Open
rtzui opened this issue Mar 9, 2013 · 2 comments
Open

Request: SimpleNumberStringParserFactory. #19

rtzui opened this issue Mar 9, 2013 · 2 comments

Comments

@rtzui
Copy link

rtzui commented Mar 9, 2013

Right now there is only one SimpleNumberStringParser, but it works only for base 10 numbers.

Think about the following code, adding a base 8 number and a base 10 number.

numberCollection = new NumberCollection();

$numberParser = new SimpleNumberStringParser(8);

$firstParsedNumber = $numberParser->parse('10');
$firstNumber = new SimpleNumber($firstParsedNumber);
$firstNumberProxy = new CollectionItemNumberProxy($firstNumber);

$numberCollection->add($firstNumberProxy);


$numberParser = new SimpleNumberStringParser();
$secondParsedNumber = $numberParser->parse('1');
$secondNumber = new SimpleNumber($secondParsedNumber);
$secondNumberProxy = new CollectionItemNumberProxy($secondNumber);

$numberCollection->add($secondNumberProxy);

$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');

$operation = new ArithmeticOperation($addition);

$engine = new Engine($operation);

$calcul = new Calcul($engine, $numberCollection);

$runner = new CalculRunner();

$runner->run($calcul);

$result = $calcul->getResult();
$numericResult = $result->getValue();  // 10

While this does still work it get ugly for international numbers my enterprise class code has to deal with: (We are a startup marketing world wide).

numberCollection = new NumberCollection();

$numberParser = new RomanNumberStringParser();

$firstParsedNumber = $numberParser->parse('XMIV');
$firstNumber = new SimpleNumber($firstParsedNumber);
$firstNumberProxy = new CollectionItemNumberProxy($firstNumber);

$numberCollection->add($firstNumberProxy);


$numberParser = new SimpleHanNumberStringParser();
$secondParsedNumber = $numberParser->parse('三十三');
$secondNumber = new SimpleNumber($secondParsedNumber);
$secondNumberProxy = new CollectionItemNumberProxy($secondNumber);

$numberCollection->add($secondNumberProxy);

$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');

$operation = new ArithmeticOperation($addition);

$engine = new Engine($operation);

$calcul = new Calcul($engine, $numberCollection);

$runner = new CalculRunner();

$runner->run($calcul);

$result = $calcul->getResult();
$numericResult = $result->getValue();  // 937

Obviously a factory for SimpleHanNumberStringParser and RomanNumberStringParser would be helpfull. It should deal with 1) encoding 2) the base of the number 3) local numerology (such a 666 or 13 in the western world or 4 in japan). I haven't figured out how to implement it, but i think it would make the code a way more productive.

@ethanresnick
Copy link

+1

@fonse
Copy link

fonse commented Mar 11, 2013

Yeah, we definitely need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants