-
Notifications
You must be signed in to change notification settings - Fork 495
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
Attempt at refactoring to_currency into base #135
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks promising we could end having fewer files, less code and providing the same functionalities. We don't really need en_EUR, en_GB, en_IN, es_CO, es_VE, fr_DZ, that were added to provide to_currency() with others currencies.
You should use static properties if that seems more appropriate to you, just let's try to make the code more "DRY" and remove the duplication!
Thanks a lot for your work and your time!
It's really appreciated!
num2words/lang_EN_EUR.py
Outdated
|
||
return self.to_splitnum(val, hightxt="euro/s", lowtxt="cents", | ||
jointxt=jointxt, longval=longval, cents=cents) | ||
pass | ||
|
||
|
||
n2w = Num2Word_EN_EUR() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now remove this file! :)
num2words/lang_EN_GB.py
Outdated
|
||
return self.to_splitnum(val, hightxt="pound/s", lowtxt="pence", | ||
jointxt="and", longval=longval) | ||
pass | ||
|
||
|
||
n2w = Num2Word_EN_GB() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now remove this file! :)
1 similar comment
I had some issues with moving uk doctests. Some of them don't pass, looks like something to do with one and feminine form. Someone native speaking should look into that. |
I think i'm done here for now. Unless you have something to add. There is some duplication left in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @shulcsm,
This looks really good!
Thanks a lot for this awesome work!
We need to handle the case of the test not passing, but first, we need to continue removing the code duplication.
Looking into the git history, the "lang_LT" was there when our college @hsoft move the project to savoirfairelinux.
So my suggestion is made the class 'Num2Word_LT' inherit from NumWord_Base, and the other class Num2Word_LV, Num2Word_PL, Num2Word_UK inherit from 'Num2Word_LT'.
Probably the contributors of Num2Word_LV, Num2Word_PL, Num2Word_UK just take Num2Word_LT as inspiration and copy/paste the code.
What do you think?
num2words/lang_EN.py
Outdated
|
||
return self.to_splitnum(val, hightxt="dollar/s", lowtxt="cent/s", | ||
jointxt="and", longval=longval, cents=True) | ||
|
||
|
||
n2w = Num2Word_EN() | ||
to_card = n2w.to_cardinal | ||
to_ord = n2w.to_ordinal | ||
to_ordnum = n2w.to_ordinal_num | ||
to_year = n2w.to_year |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove this..
I don't want to make inheritance chain deeper and only thing that would solve is get rid of duplication for |
@shulcsm OK, you have convinced me, let's not make the inheritance chain deeper... We will try to push it to the base and generalize all implementations. I will only try to find the way or the person to verify the tests and implementation of UK before merge this and break something. I will try to look at this in the next day. |
Ok. Failing tests have nothing to do with changes, though. It was in broken state before I touched it. |
@shulcsm if it is the case, then I will trust you here and accept this so we can move forward in fixing the test and pushing to_cadinal to the base class so we could remove the code duplication. |
Thanks, here is an issue for tests: #138 |
👍 thanks @shulcsm |
Status
Additional notes
Attempt at generalizing and moving
to_currency
down as discussed in #133If this is fine i can do it to rest of mentioned languages.
However i'm not happy with
Num2Word_Base
and how it works. I'm not sure how to do rest of integration. What is the purpose of all these initialization callbacks? Shouldn't static things be better off as static properties?