Class: Experian::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Report

Returns a new instance of Report.



8
9
10
11
12
13
14
15
16
# File 'lib/experian/report.rb', line 8

def initialize(response)
  @response = response
  @url = response.env.url.to_s
  @raw_xml = response.body
  MultiXml.parser = :rexml
  @xml = MultiXml.parse(@raw_xml)

  raise Experian::AuthenticationError if authentication_error?
end

Instance Attribute Details

#raw_xmlObject (readonly)

Returns the value of attribute raw_xml.



6
7
8
# File 'lib/experian/report.rb', line 6

def raw_xml
  @raw_xml
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/experian/report.rb', line 6

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/experian/report.rb', line 6

def url
  @url
end

#xmlObject (readonly)

Returns the value of attribute xml.



6
7
8
# File 'lib/experian/report.rb', line 6

def xml
  @xml
end

Instance Method Details

#addressObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/experian/report.rb', line 30

def address
  if (address_xml = data["DomicilioComercial"])
    OpenStruct.new(
      line: address_xml["Domicilio"],
      city: address_xml["Poblacion"],
      province: address_xml["Provincia"],
      postal_code: address_xml["CodigoPostal"],
      municipality: address_xml["Municipio"],
    )
  end
end

#cnaeObject



60
61
62
# File 'lib/experian/report.rb', line 60

def cnae
  data.dig("ActividadComercial", "Cnae")&.first&.dig("Codigo")&.to_i
end

#idObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/experian/report.rb', line 18

def id
  if (id_xml = data["DatosIdentificativos"])
    OpenStruct.new(
      cif: id_xml["Cif"],
      name: id_xml["Nombre"],
      infotel_code: id_xml["CodigoInfotel"],
      incorporation_date: Date.parse(id_xml["FechaFundacion"]),
      social_form: id_xml["FormaSocial"]["__content__"],
    )
  end
end

#number_of_employeesObject

Number of employees in the last recorded excercise



43
44
45
# File 'lib/experian/report.rb', line 43

def number_of_employees
  data.dig("ListaAnualEmpleados", "Empleado")&.first&.dig("EmpleadoFijo")&.to_i
end

#ratingObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/experian/report.rb', line 47

def rating
  if (rating_xml = data["Rating"])
    return unless rating_xml["RatingAxesorDef"]

    OpenStruct.new(
      score: rating_xml["RatingAxesorDef"]&.strip&.to_i,
      default_probability: rating_xml["ProbImpago"]&.to_f,
      risk: rating_xml["GrupoRiesgo"],
      size: rating_xml["Tamaño"],
    )
  end
end