-
Notifications
You must be signed in to change notification settings - Fork 15
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
Multi part validation #5
Conversation
CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME-RBK1', 6).wont_be_nil | ||
CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME-RBK2', 6).must_be_nil | ||
CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME-RBK1', parts: 6).wont_be_nil | ||
CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME-RBK2', parts: 6).must_be_nil |
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.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
parts = code.scan(/[0-9A-Z]{#{LENGTH}}/) | ||
def self.validate(orig, options = { parts: @@parts }) | ||
num_parts = options.delete(:parts) | ||
code = orig.upcase.gsub(/[^0-9A-Z]+/, '') |
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.
Unnecessary spacing detected.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
def self.validate(orig, options = { parts: @@parts }) | ||
num_parts = options.delete(:parts) | ||
code = orig.upcase.gsub(/[^0-9A-Z]+/, "") | ||
parts = code.scan(/[0-9A-Z]{#{LENGTH}}/) |
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.
Unnecessary spacing detected.
Thanks for contributing @gee-forr. Sorry for being late. I've been sick for the last couple days 😢 As you pointed out, I agree that those However I'd prefer to leave current interface as it is because changing The end result will look like: CouponCode.configure do |c|
c.parts = 5
c.length = 6
c.separator = '-'
end I believe this approach will provide with more convenient use cases. You can find working in progress code at #6. Please feel free to create another PR for other implementation suggestions. |
I updated README to make that multi-part validation clearer for now: 0d40bb4. Thanks again for your time and effort and my apology for being late 😭 I will be adding configuration as soon as possible. |
Hi there,
I came across an issue where I couldn't validate codes longer than 3 parts. Turns out, it wasnt documented, and I just needed to add the parts as a second positional argument.
This however is inconsistent with the interface for the generate method.
I've updated the validate method's arguments to match those of generates, and have also added a feature to set a default parts length.
I've also updated the readme (but only in english, I don't speak Korean unfortunately), and bumped the version.
I hope you find the changes to your liking :) Thanks again.