Class: Hamburglar::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/hamburglar/report.rb

Overview

Hamburglar::Report is the main class for generating fraud reports

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Report



10
11
12
13
14
# File 'lib/hamburglar/report.rb', line 10

def initialize(params = {})
  @gateway  = params.delete(:gateway) || Hamburglar.config.gateway
  @params   = params
  @response = generate_report!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/hamburglar/report.rb', line 16

def method_missing(method, *args, &block)
  if @response && @response[method.to_sym]
    @response[method.to_sym]
  else
    super
  end
end

Instance Attribute Details

#paramsObject (readonly)

Parameters that will be used to generate this fraud report



5
6
7
# File 'lib/hamburglar/report.rb', line 5

def params
  @params
end

#responseObject (readonly)

Response from gateway



8
9
10
# File 'lib/hamburglar/report.rb', line 8

def response
  @response
end

Instance Method Details

#fraud?Boolean



28
29
30
31
32
33
34
35
36
# File 'lib/hamburglar/report.rb', line 28

def fraud?
  @fraud = true if @response.nil? || @response.empty?
  return @fraud if @fraud
  if Hamburglar.config.fraud_proc.nil?
    @fraud = @response[:score].to_f >= Hamburglar.config.fraud_score.to_f
  else
    @fraud = Hamburglar.config.fraud_proc.call(self) == true
  end
end

#respond_to?(key) ⇒ Boolean



24
25
26
# File 'lib/hamburglar/report.rb', line 24

def respond_to?(key)
  @response.has_key?(key) || super
end