Permalink
Browse files

refactored getting input in email parser example

Someone wondering how to use the parser can read the last line with less confusion, since the input-reading has been grouped into a single, separate section. Also, the default input is specified DRYly.
  • Loading branch information...
1 parent 39750be commit ca0ef80ea9195c582b167cf3827ca69af3f7ca5e @roryokane roryokane committed Apr 7, 2013
Showing with 5 additions and 3 deletions.
  1. +5 −3 example/email_parser.rb
View
@@ -44,9 +44,11 @@ class EmailSanitizer < Parslet::Transform
parser = EmailParser.new
sanitizer = EmailSanitizer.new
-unless ARGV[0]
+input = ARGV[0] || begin
+ default = "a.b.c.d@gmail.com"
STDERR.puts "usage: #{$0} \"EMAIL_ADDR\""
- STDOUT.puts "since you haven't specified any EMAIL_ADDR, for testing purposes we're using a.b.c.d@gmail.com"
+ STDOUT.puts "since you haven't specified any EMAIL_ADDR, for testing purposes we're using #{default}"
+ default
end
-p sanitizer.apply(parser.parse_with_debug(ARGV[0] || 'a.b.c.d@gmail.com'))
+p sanitizer.apply(parser.parse_with_debug(input))

0 comments on commit ca0ef80

Please sign in to comment.