Class: CPRClient::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/cpr_client/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_doc) ⇒ Record

Returns a new Response.

Parameters:

  • xml_doc

    a Nokogiri::XML object



9
10
11
12
# File 'lib/cpr_client/record.rb', line 9

def initialize(xml_doc)
  @timestamp = xml_doc.at_css("CprServiceHeader[r='STAMP']")['ts']
  @fields    = extract_fields(xml_doc)
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



4
5
6
# File 'lib/cpr_client/record.rb', line 4

def fields
  @fields
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



4
5
6
# File 'lib/cpr_client/record.rb', line 4

def timestamp
  @timestamp
end

Instance Method Details

#addressObject

Returns the record’s address if present.

The address will be a string of the fields STADR, POSTNR and POSTNR’s t attribute.

Fx. Boulevarden 101,1 mf, 6800 Varde

Returns:

  • string with address or nil



47
48
49
50
# File 'lib/cpr_client/record.rb', line 47

def address
  values = [ get(:stadr), get(:postnr), get(:postnr, :t) ]
  '%s, %s %s' % values if values.all?
end

#birthdayObject

Returns the birthday as Date.

Returns:

  • Date with date of birth



35
36
37
# File 'lib/cpr_client/record.rb', line 35

def birthday
  Date.parse(get(:foeddato))
end

#get(name, value = 'v') ⇒ Object Also known as: []

Gets the value of a field with the given name.

Parameters:

  • name

    the name of the target field.

  • value (defaults to: 'v')

    the name of the value attribute



18
19
20
21
# File 'lib/cpr_client/record.rb', line 18

def get(name, value = 'v')
  field = @fields[name.to_s.upcase]
  field[value.to_s.downcase] if field
end

#protected?Boolean

Returns true if the person has name/address protection.

Returns:

  • (Boolean)

    true if protected, false otherwise



28
29
30
# File 'lib/cpr_client/record.rb', line 28

def protected?
  get(:beskyt) == '1'
end