Skip to content

Commit

Permalink
Clean up generate_handle method (use returning and perform one transf…
Browse files Browse the repository at this point in the history
…ormation per line).
  • Loading branch information
alexreisner committed Sep 3, 2009
1 parent cc66d4d commit 670d124
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ def handle_based_on(attribute, options = {})
# Generate a URL-friendly name.
#
define_method :generate_handle do
str = send(attribute)
return nil unless str.is_a?(String)
str = str.downcase.strip.gsub('&', ' and ') # add space for, e.g., "Y&T"
str = str.delete('.\'"') # no space
str = str.gsub(/\W/, ' ') # space
str.gsub(/ +/, options[:separator])
returning send(attribute) do |str|
str.downcase!
str.strip!
str.gsub!('&', ' and ') # add space for, e.g., "Y&T"
str.delete!('.\'"') # no space
str.gsub!(/\W/, ' ') # space
str.gsub!(/ +/, options[:separator])
end
end

##
Expand Down

0 comments on commit 670d124

Please sign in to comment.