Sha256: f07773134aacd5452fcc3561287ffc87ab7df91fd56dd109827a724edc596fce

Contents?: true

Size: 1.4 KB

Versions: 106

Compression:

Stored size: 1.4 KB

Contents

unit uBob;

interface

type
  TBob = Class
  private
    class function IsSilence(aStatement: string): Boolean; static;
    class function IsYelling(aStatement: string): Boolean; static;
    class function IsQuestion(aStatement: string): Boolean; static;
    class function IsYellingQuestion(aStatement: string): Boolean; static;
  public
    class function Response(aStatement: string): string; static;
  End;

implementation
uses RegularExpressions, System.SysUtils;

class function TBob.IsSilence(aStatement: string): Boolean;
begin
  result := aStatement.Trim = '';
end;

class function TBob.IsYelling(aStatement: string): Boolean;
begin
  result := (aStatement.ToUpper = aStatement) and TRegEx.IsMatch(aStatement, '[a-zA-Z]+');
end;

class function TBob.IsYellingQuestion(aStatement: string): Boolean;
begin
  result := IsQuestion(aStatement) and IsYelling(aStatement);
end;

class function TBob.IsQuestion(aStatement: string): Boolean;
begin
  result := aStatement.Trim.EndsWith('?');
end;

class function TBob.Response(aStatement: string): string;
begin
  if IsSilence(aStatement) then
    result := 'Fine. Be that way!'
  else
    if IsYellingQuestion(aStatement) then
      result := 'Calm down, I know what I''m doing!'
    else
    if IsYelling(aStatement) then
      result := 'Whoa, chill out!'
    else
      if IsQuestion(aStatement) then
        result := 'Sure.'
      else
        result := 'Whatever.';
end;

end.

Version data entries

106 entries across 106 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.179 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.178 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.177 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.176 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.175 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.174 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.173 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.172 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.171 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.170 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.169 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.167 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.166 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.165 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.164 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.163 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.162 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.161 tracks/delphi/exercises/bob/uBobExample.pas
trackler-2.2.1.160 tracks/delphi/exercises/bob/uBobExample.pas