afc_salesforce 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/README.md +1 -0
  8. data/Rakefile +6 -0
  9. data/afc_salesforce.gemspec +40 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/afc_salesforce.rb +56 -0
  13. data/lib/afc_salesforce/account.rb +61 -0
  14. data/lib/afc_salesforce/additional_income.rb +12 -0
  15. data/lib/afc_salesforce/ahc_realtor.rb +0 -0
  16. data/lib/afc_salesforce/asset.rb +13 -0
  17. data/lib/afc_salesforce/base.rb +11 -0
  18. data/lib/afc_salesforce/borrower.rb +36 -0
  19. data/lib/afc_salesforce/configuration.rb +16 -0
  20. data/lib/afc_salesforce/forms/agent_referral.rb +50 -0
  21. data/lib/afc_salesforce/forms/long_purchase.rb +56 -0
  22. data/lib/afc_salesforce/forms/long_refinance.rb +56 -0
  23. data/lib/afc_salesforce/forms/short_lead.rb +48 -0
  24. data/lib/afc_salesforce/lead.rb +31 -0
  25. data/lib/afc_salesforce/models/account.rb +267 -0
  26. data/lib/afc_salesforce/models/ahc_realtor.rb +67 -0
  27. data/lib/afc_salesforce/models/asset.rb +35 -0
  28. data/lib/afc_salesforce/models/base.rb +17 -0
  29. data/lib/afc_salesforce/models/concerns/type_setter.rb +23 -0
  30. data/lib/afc_salesforce/models/contact.rb +152 -0
  31. data/lib/afc_salesforce/models/income.rb +25 -0
  32. data/lib/afc_salesforce/models/lead.rb +118 -0
  33. data/lib/afc_salesforce/tools.rb +4 -0
  34. data/lib/afc_salesforce/tools/utilities.rb +45 -0
  35. data/lib/afc_salesforce/tools/validation.rb +18 -0
  36. data/lib/afc_salesforce/tools/validation/rule/email.rb +58 -0
  37. data/lib/afc_salesforce/tools/validation/rule/instance_of.rb +36 -0
  38. data/lib/afc_salesforce/tools/validation/rule/length.rb +52 -0
  39. data/lib/afc_salesforce/tools/validation/rule/matches.rb +44 -0
  40. data/lib/afc_salesforce/tools/validation/rule/not_empty.rb +32 -0
  41. data/lib/afc_salesforce/tools/validation/rule/not_nil.rb +32 -0
  42. data/lib/afc_salesforce/tools/validation/rule/numeric.rb +32 -0
  43. data/lib/afc_salesforce/tools/validation/rule/phone.rb +51 -0
  44. data/lib/afc_salesforce/tools/validation/rule/regular_expression.rb +33 -0
  45. data/lib/afc_salesforce/tools/validation/validator.rb +128 -0
  46. data/lib/afc_salesforce/version.rb +3 -0
  47. metadata +194 -0
@@ -0,0 +1,45 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ class UnsupportedTypeError < StandardError; end
4
+
5
+ class Utilities
6
+ SUPPORTED_TYPES = [:integer, :float, :date, :boolean].freeze
7
+
8
+ def self.parse_by_type(input, type)
9
+ return input if input.nil?
10
+ raise UnsupportedTypeError unless SUPPORTED_TYPES.include?(type)
11
+
12
+ output = input
13
+ case type
14
+ when :integer
15
+ output_sub = input.to_s.sub(/,/,'')
16
+ output_match = output_sub.match(/[0-9|\.]+/)
17
+ output = output_match.to_s.to_i
18
+ when :float
19
+ output_sub = input.to_s.sub(/,/,'')
20
+ output_match = output_sub.match(/[0-9|\.]+/)
21
+ output = output_match.to_s.to_f
22
+ when :date
23
+ begin
24
+ parsed_date = Time.strptime(input, "%m/%d/%Y")
25
+ output = parsed_date.strftime("%Y-%m-%d")
26
+ rescue ArgumentError => e
27
+ output = input
28
+ end
29
+ when :boolean
30
+ output = false
31
+ if input == false || input == '0' || input == 0
32
+ output = false
33
+ end
34
+
35
+ if input == true || input == '1' || input == 1
36
+ output = true
37
+ end
38
+ output
39
+ end
40
+
41
+ return output
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'validation/validator'
2
+
3
+ module AFCSalesforce
4
+ module Tools
5
+ module Validation
6
+
7
+ class << self
8
+ private
9
+
10
+ def included(mod)
11
+ mod.module_eval do
12
+ extend AFCSalesforce::Tools::Validation::Rule
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,58 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Email rule class. This rule was adapted from https://github.com/emmanuel/aequitas/blob/master/lib/aequitas/rule/format/email_address.rb
6
+
7
+ class Email
8
+ EMAIL_ADDRESS = begin
9
+ letter = 'a-zA-Z'
10
+ digit = '0-9'
11
+ atext = "[#{letter}#{digit}\!\#\$\%\&\'\*+\/\=\?\^\_\`\{\|\}\~\-]"
12
+ dot_atom_text = "#{atext}+([.]#{atext}*)+"
13
+ dot_atom = dot_atom_text
14
+ no_ws_ctl = '\x01-\x08\x11\x12\x14-\x1f\x7f'
15
+ qtext = "[^#{no_ws_ctl}\\x0d\\x22\\x5c]" # Non-whitespace, non-control character except for \ and "
16
+ text = '[\x01-\x09\x11\x12\x14-\x7f]'
17
+ quoted_pair = "(\\x5c#{text})"
18
+ qcontent = "(?:#{qtext}|#{quoted_pair})"
19
+ quoted_string = "[\"]#{qcontent}+[\"]"
20
+ atom = "#{atext}+"
21
+ word = "(?:#{atom}|#{quoted_string})"
22
+ obs_local_part = "#{word}([.]#{word})*"
23
+ local_part = "(?:#{dot_atom}|#{quoted_string}|#{obs_local_part})"
24
+ dtext = "[#{no_ws_ctl}\\x21-\\x5a\\x5e-\\x7e]"
25
+ dcontent = "(?:#{dtext}|#{quoted_pair})"
26
+ domain_literal = "\\[#{dcontent}+\\]"
27
+ obs_domain = "#{atom}([.]#{atom})+"
28
+ domain = "(?:#{dot_atom}|#{domain_literal}|#{obs_domain})"
29
+ addr_spec = "#{local_part}\@#{domain}"
30
+ pattern = /\A#{addr_spec}\z/u
31
+ end
32
+
33
+ # Determines if value is a valid email
34
+ def valid_value?(value)
35
+ !!EMAIL_ADDRESS.match(value)
36
+ end
37
+
38
+ def error(value)
39
+ results = {}
40
+ results[:expected] = true
41
+ results[:got] = valid_value?(value)
42
+ results
43
+ end
44
+
45
+ # The error key for this rule
46
+ def error_key
47
+ :email
48
+ end
49
+
50
+ # This rule has no params
51
+ def params
52
+ {}
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,36 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Rule for instance of
6
+ class InstanceOf
7
+ def initialize(instance_name)
8
+ @instance_name = instance_name
9
+ end
10
+
11
+ def params
12
+ @instance_name
13
+ end
14
+
15
+ def error(value)
16
+ results = {}
17
+ results[:expected] = @instance_name
18
+ results[:got] = value.class
19
+ results
20
+ end
21
+
22
+ # Determines if value is empty or not. In this rule, nil is empty
23
+ def valid_value?(value)
24
+ return true if value.nil?
25
+ value.class == @instance_name
26
+ end
27
+
28
+ # The error key for this field
29
+ def error_key
30
+ :instance_of
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Length rule
6
+ class Length
7
+ # params can be any of the following:
8
+ #
9
+ # - :minimum - at least this many chars
10
+ # - :maximum - at most this many chars
11
+ # - :exact - exactly this many chars
12
+ #
13
+ # Example:
14
+ #
15
+ # {minimum: 3, maximum: 10}
16
+ # {exact: 10}
17
+ def initialize(params)
18
+ @params = params
19
+ end
20
+
21
+ # returns the params given in the constructor
22
+ def params
23
+ @params
24
+ end
25
+
26
+
27
+ def error(value)
28
+ results = {}
29
+ results[:expected] = @params
30
+ results[:got] = value.length
31
+ results
32
+ end
33
+
34
+ # determines if value is valid according to the constructor params
35
+ def valid_value?(value)
36
+ @params.each_pair do |key, param|
37
+ return false if key == :minimum && (value.nil? || value.length < param)
38
+ return false if key == :maximum && !value.nil? && value.length > param
39
+ return false if key == :exact && (value.nil? || value.length != param)
40
+ end
41
+
42
+ true
43
+ end
44
+
45
+ def error_key
46
+ :length
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,44 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Matches rule
6
+ class Matches
7
+ attr_writer :obj
8
+
9
+ # This class should take the field to match with in the constructor:
10
+ #
11
+ # rule = Validation::Rule::Matches(:password)
12
+ # rule.obj = OpenStruct.new(:password => 'foo')
13
+ # rule.valid_value?('foo')
14
+ def initialize(matcher_field)
15
+ @matcher_field = matcher_field
16
+ end
17
+
18
+ # The error key for this rule
19
+ def error_key
20
+ :matches
21
+ end
22
+
23
+ def error(value)
24
+ results = {}
25
+ results[:expected] = value
26
+ results[:got] = @obj.send(@matcher_field)
27
+ results
28
+ end
29
+
30
+ # Params is the matcher_field given in the constructor
31
+ def params
32
+ @matcher_field
33
+ end
34
+
35
+ # Determines if value matches the field given in the constructor
36
+ def valid_value?(value)
37
+ matcher_value = @obj.send(@matcher_field)
38
+ matcher_value == value
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Rule for not empty
6
+ class NotEmpty
7
+ # This rule has no params
8
+ def params
9
+ {}
10
+ end
11
+
12
+ def error(value)
13
+ results = {}
14
+ results[:expected] = true
15
+ results[:got] = valid_value?(value)
16
+ results
17
+ end
18
+
19
+ # Determines if value is empty or not. In this rule, nil is empty
20
+ def valid_value?(value)
21
+ ! (value.nil? || value.empty?)
22
+ end
23
+
24
+ # The error key for this field
25
+ def error_key
26
+ :not_empty
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Rule for not nil
6
+ class NotNil
7
+ # This rule has no params
8
+ def params
9
+ {}
10
+ end
11
+
12
+ def error(value)
13
+ results = {}
14
+ results[:expected] = true
15
+ results[:got] = valid_value?(value)
16
+ results
17
+ end
18
+
19
+ # Determines if value is nil or not.
20
+ def valid_value?(value)
21
+ !value.nil?
22
+ end
23
+
24
+ # The error key for this field
25
+ def error_key
26
+ :not_nil
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # rule for numeric values
6
+ class Numeric
7
+ # Determines if value is numeric. It can only contain whole numbers
8
+ def valid_value?(value)
9
+ !!/^[0-9]+$/.match(value.to_s)
10
+ end
11
+
12
+ def error(value)
13
+ results = {}
14
+ results[:expected] = true
15
+ results[:got] = valid_value?(value)
16
+ results
17
+ end
18
+
19
+ # The error key for this rule
20
+ def error_key
21
+ :numeric
22
+ end
23
+
24
+ # this rule has no params
25
+ def params
26
+ {}
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ # Phone rule
6
+ class Phone
7
+ # params can be any of the following:
8
+ #
9
+ # - :format - the phone number format
10
+ #
11
+ # Example:
12
+ #
13
+ # {:format => :america}
14
+ def initialize(params = {:format => :america})
15
+ @params = params
16
+ end
17
+
18
+ # returns the params given in the constructor
19
+ def params
20
+ @params
21
+ end
22
+
23
+ def error(value)
24
+ digits = value.gsub(/\D/, '').split(//)
25
+ results = {}
26
+ results[:expected] = true
27
+ results[:got] = valid_value?(value)
28
+ results
29
+ end
30
+
31
+ # determines if value is valid according to the constructor params
32
+ def valid_value?(value)
33
+ send(@params[:format], value)
34
+ end
35
+
36
+ def error_key
37
+ :phone
38
+ end
39
+
40
+ protected
41
+
42
+ def america(value)
43
+ digits = value.gsub(/\D/, '').split(//)
44
+
45
+ digits.length == 10 || digits.length == 11
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ module AFCSalesforce
2
+ module Tools
3
+ module Validation
4
+ module Rule
5
+ class RegularExpression
6
+
7
+ def initialize(params)
8
+ @params = params
9
+ end
10
+
11
+ def error(value)
12
+ results = {}
13
+ results[:expected] = true
14
+ results[:got] = valid_value?(value)
15
+ results
16
+ end
17
+
18
+ def error_key
19
+ :regular_expression
20
+ end
21
+
22
+ def valid_value?(value)
23
+ value.nil? || !!@params[:regex].match(value)
24
+ end
25
+
26
+ def params
27
+ @params
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end