Permalink
Browse files

Extract Class Step Three

* Move another method
* This method requires moving a constant
* Also requires changing the view to reference to the new class
  • Loading branch information...
jferris committed Feb 14, 2013
1 parent ac01475 commit 0fefb969916cf35dc6af511f3941d3a09ff27a4d
@@ -1,8 +1,7 @@
class InvitationsController < ApplicationController
EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/

def new
@survey = Survey.find(params[:survey_id])
@survey_inviter = SurveyInviter.new('')
end

def create
@@ -37,11 +36,7 @@ def valid_message?
end

def invalid_recipients
@invalid_recipients ||= recipient_list.map do |item|
unless item.match(EMAIL_REGEX)
item
end
end.compact
@survey_inviter.invalid_recipients
end

def recipient_list
@@ -1,8 +1,18 @@
class SurveyInviter
EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/

def initialize(recipients)
@recipients = recipients
end

def invalid_recipients
@invalid_recipients ||= recipient_list.map do |item|
unless item.match(EMAIL_REGEX)
item
end
end.compact
end

def recipient_list
@recipient_list ||= @recipients.gsub(/\s+/, '').split(/[\n,;]+/)
end
@@ -4,10 +4,10 @@
<div class="error">Please provide a message</div>
<% end %>
<%= f.input :recipients, as: :text, input_html: { value: @recipients } %>
<% if @invalid_recipients %>
<% if @survey_inviter.invalid_recipients %>
<div class="error">
Invalid email addresses:
<%= @invalid_recipients.join(', ') %>
<%= @survey_inviter.invalid_recipients.join(', ') %>
</div>
<% end %>
<%= f.button :submit, value: 'Invite' %>

0 comments on commit 0fefb96

Please sign in to comment.