Class: Arbetsformedlingen::Company

Inherits:
Model
  • Object
show all
Defined in:
lib/arbetsformedlingen/models/company.rb

Instance Attribute Summary

Attributes inherited from Model

#schema

Instance Method Summary collapse

Methods inherited from Model

#errors, from_schema, #valid?

Constructor Details

#initialize(hash) ⇒ Company

Returns a new instance of Company.



27
28
29
# File 'lib/arbetsformedlingen/models/company.rb', line 27

def initialize(hash)
  super(CompanySchema.call(hash))
end

Instance Method Details

#cin_arbetsformedlingen(cin) ⇒ Object

Formats a Company Identification Number the way Arbetsformedlingen likes it



44
45
46
47
48
49
# File 'lib/arbetsformedlingen/models/company.rb', line 44

def cin_arbetsformedlingen(cin)
  String.new(cin.dup).
    delete('-').
    insert(6, '-').
    insert(0, '46-')
end

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/arbetsformedlingen/models/company.rb', line 31

def to_h
  hash = super
  address = hash.fetch(:address)
  hash[:address][:full_address] = [
    address.fetch(:street),
    address.fetch(:zip),
    address.fetch(:city),
  ].join(', ')
  hash[:cin_arbetsformedlingen] = cin_arbetsformedlingen(hash.fetch(:cin))
  hash
end