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

Extract parts of long Monetize#extract_cents into methods #11

Closed
wants to merge 1 commit into from
Closed

Extract parts of long Monetize#extract_cents into methods #11

wants to merge 1 commit into from

Conversation

allolex
Copy link
Contributor

@allolex allolex commented Apr 18, 2014

  • Moved regular expression into constant
  • Used regexes more idiomatically, e.g. \D instead of [^\d]
  • .negative? tells you whether the number is negative
  • .contains_hyphen? tells you whether the number contains a hyphen
  • .strip_negative_symbols removes minus signs from numbers

- Moved regular expression into constant
- Used regexes more idiomatically, e.g. \D instead of [^\d]
- .negative? tells you whether the number is negative
- .contains_hyphen? tells you whether the number contains a hyphen
- .strip_negative_symbols removes minus signs from numbers
@allolex
Copy link
Contributor Author

allolex commented Apr 18, 2014

When I get a chance, I'll have a go at tidying up the code that recognises what is what based on the delimiters. :)

num = input.gsub(/[^\d.,'-]/, '')

negative = num =~ /^-|-$/ ? true : false
@original_number = num = input.gsub(/[^\d.,'-]/, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only question I have, why an instance variable here? Why not make a memoized method instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. To be honest, I plan to factor that variable out as well. It
was just easy to do it this way. These are just the first steps.

For now, why don't you just leave the PR unmerged and I'll stick my other
changes in the same branch so they show up here?

Damon Davison
http://allolex.net
@allolex

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a good plan

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

Successfully merging this pull request may close these issues.

None yet

2 participants