0

次の構文エラー メッセージが表示されました。

/usr/src/check_in/lib/check_in.rb:105: 構文エラー、予期しない keyword_end、'}' が必要です

class CheckIn < Adhearsion::CallController
  def run
  answer
  #play 'welcome.wav' # "Welcome to the PSG check in application."
  logger.info "#{call.from.to_s} called at #{time.now.to_s}"
  if verify_phone(call.from) == false # If it's not a site phone
    logger.info "Number not recognised, routing to Ops" 
    #play 'not_site_phone.wav' # "Number not recognized." 
  #dial(sip:number) # Dial operations
  hangup 
  else 
    user = verify_uid # Checks the User Id
  end
  if to_check_out?(user.uid)
check_out(user.uid)
  else
update_shift(user.uid)
    #play 'thank_you.wav'
  end
end

def verify_uid
  count = 1 # Generic count variable
  input = ask 'enter_uid.wav', :limit => 5, :timeout => 5.seconds #takes user ID as DTMF
  while (count <= 3 ) # Tracks the number of attempts
    if User.find_by_uid(input.response) == nil # If user.find doesn't return anything
  logger.info "Invalid user ID. ID entered = #{input.response} Attepmt = #{count}"
      input = ask "please_try_again.wav", :limit => 5, :timeout => 10.seconds
  count += 1 # Get user to try again
    elsif count == 3 
    play "try_again_later.wav" #"Please try you again later"
    logger.info "Tries exceeded, played try again later."
    hangup
    else
  @user = User.find_by_uid(input) # Assigns the user variable to return.
  logger.info "User ID: #{@user.uid} is valid"
  return @user
      end
    end
  end

  def verify_phone(caller_id)
    if Sites.find_by_site_phone(caller_id) != nil
    return true
    else
    return false  
    end
  end    

  def update_shift (user_id)
     @user = User.find_by_uid(user_id) # Grabs the user object
     if (@user.checked_in?) # If the user is already checked in assign the relevant attributes
    @user.time_olc = time.now 
    @user.num_ci += 1
    @user.check_in.create_check_in(:site_id => @user.site_id, uid => @user.uid, :time => time.now) 
    logger.info "#{@user.uid} checked in at #{@user.time_olc}"
     else # Otherwise set all the attributes for the shift
    @user.update_attributes(:checked_in? => true, :time_in => time.now, :time_olc => time.now, :num_ci => 1, :site_id => @user.site.find_by_site_phone(call.from))
    @user.check_in.create_check_in(:site_id => @user.site_id, uid => @user.uid, :time => time.now)
    logger.info "#{@user.uid} punched in at #{@user.time_in}"
     end
  end

  def to_check_out?(user_id) # Method to see if the user has reached check out
    @user = User.find_by_uid(user_id)
    num_of_ci = @user.num_ci + @user.num_notifications
    if (num_of_ci >= @user.site.shift_len)
      return true
    else
      return false
    end
  end

  def check_out!(user_id)
    @user = User.find_by_uid(user_id)
    input = ask 'check_out?.wav', :limit => 1, :timeout => 5.seconds
    if (input == 1)
      update(@user.uid)
    else
      @user.time_out = time.now
      @user.time_olc = time.now
      @user.update_attributes(:checked_in => false)
    end
    report_for_user(uid)
  end

  def secure
    count = 1
    play 'secure.wav'
    sec = 5.times.map {Random.rand(0..9)
    result = ask %w"#{sec[0]}, #{sec[1]}, #{sec[2]}, #{sec[3]}, #{sec[4]}", :limit => 5, :timeout => 5.seconds
    while (count <= 3)
      if (sec.join == result.response)
    logger.info "Check in valid"
    return true
      elsif (count < 3)
       result = ask 'please_try_again.wav', :limit => 5, :timeout => 5.seconds
      else
    play 'try_again_later.wav'
    hangup
      end
    end
  end

  def report_for_user(user_id)
    @user = Users.find_by_uid(user_id)
    report = file.open("/report/#{user_id}-#{@user.site_id}-#{date.current}",w)
    user_check_ins = @user.check_in.all
    report.write("Time, Site ID, User ID")
    user_check_ins.each do |check_in|
    report.write("#{user.check_in.time}, #{user.check_in.site_id}, #{user.checkin.uid}")
    check_in.destroy
    end
  end

  def notify
    foo = Users.all
    foo.each do |user|
      if user.checked_in?
    t1 = Time.now #sets a time place holder
    t2 = user.time_olc
        convert_time = (t1.hour * 60 * 60) + (t1.min * 60) + t1.sec
    convert_tolc = (t2.hour * 60 * 60) + (t2.min * 60) + t1.sec
    if ((convert_time - convert_tolc)/60 > 75)
      user.num_notification += 1
      a = user.uid.to_s
          logger.info "#{user.uid} hasn't checked in this hour"
#         Adhearsion::OutboundCall.originate '+tel: Mobile' :from => ' ' do
#           answer
#           play a[0], a[1], a[2], a[3], a[4], 'has_not_checked_in.wav'
#           hangup
#         end
        end
      end
    end
  end 
end  
4

2 に答える 2

5

このメソッドでは、中かっこ '{' を 1 つ開いていますが、閉じていません。

def secure
count = 1
play 'secure.wav'
sec = 5.times.map {Random.rand(0..9)
result = ask %w"#{sec[0]}, #{sec[1]}, #{sec[2]}, #{sec[3]}, #{sec[4]}", :limit => 5, :timeout => 5.seconds
while (count <= 3)
  if (sec.join == result.response)
logger.info "Check in valid"
return true
  elsif (count < 3)
   result = ask 'please_try_again.wav', :limit => 5, :timeout => 5.seconds
  else
play 'try_again_later.wav'
hangup
  end
end
end
于 2012-11-27T04:24:00.503 に答える
1

次の行のセキュア メソッドに右中括弧がありません

sec = 5.times.map {Random.rand(0..9)
于 2012-11-27T04:24:04.137 に答える