Class: CPRClient::Record
- Inherits:
-
Object
- Object
- CPRClient::Record
- Defined in:
- lib/cpr_client/record.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#address ⇒ Object
Returns the record’s address if present.
-
#birthday ⇒ Object
Returns the birthday as Date.
-
#get(name, value = 'v') ⇒ Object
(also: #[])
Gets the value of a field with the given name.
-
#initialize(xml_doc) ⇒ Record
constructor
Returns a new Response.
-
#protected? ⇒ Boolean
Returns true if the person has name/address protection.
Constructor Details
#initialize(xml_doc) ⇒ Record
Returns a new Response.
9 10 11 12 |
# File 'lib/cpr_client/record.rb', line 9 def initialize(xml_doc) = xml_doc.at_css("CprServiceHeader[r='STAMP']")['ts'] @fields = extract_fields(xml_doc) end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
4 5 6 |
# File 'lib/cpr_client/record.rb', line 4 def fields @fields end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/cpr_client/record.rb', line 4 def end |
Instance Method Details
#address ⇒ Object
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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cpr_client/record.rb', line 47 def address street_and_number = "#{get(:vejkod, :t)} #{get_clean(:husnr)}" postal_district = "#{get(:postnr)} #{get(:postnr, :t)}" door = get_clean(:sidedoer) floor = get_clean(:etage) if floor and door "#{street_and_number}, #{floor}. #{door}, #{postal_district}" elsif floor "#{street_and_number}, #{floor}., #{postal_district}" else "#{street_and_number}, #{postal_district}" end end |
#birthday ⇒ Object
Returns the birthday as Date.
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.
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.
28 29 30 |
# File 'lib/cpr_client/record.rb', line 28 def protected? get(:beskyt) == '1' end |