Skip to content

Commit

Permalink
AF compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
buren committed May 22, 2017
1 parent 27a45d2 commit f2e83e8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
2 changes: 2 additions & 0 deletions data/municipality-codes.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Unspecified workplace within Sweden,9090
Any country outside of Sweden,9999
Ale,1440
Alingsås,1489
Alvesta,0764
Expand Down
2 changes: 1 addition & 1 deletion lib/arbetsformedlingen/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def self.post_job_url
ROUTES.fetch(:post_job_url)
end
end
end
end
5 changes: 4 additions & 1 deletion lib/arbetsformedlingen/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def to_h

# Formats a Company Identification Number the way Arbetsformedlingen likes it
def cin_arbetsformedlingen(cin)
String.new(cin.dup).insert(6, '-').insert(0, '46-')
String.new(cin.dup).
delete('-').
insert(6, '-').
insert(0, '46-')
end
end
end
5 changes: 4 additions & 1 deletion lib/arbetsformedlingen/models/packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ module Arbetsformedlingen
end

class Packet < Model
DEFAULT_PACKET_ID = 1

def initialize(attributes:, publication:, document:, position:)
hash = attributes
@publication = publication
@document = document
@position = position
super(PacketSchema.call(hash.merge(id: hash[:job_id])))
id = hash.fetch(:id, DEFAULT_PACKET_ID)
super(PacketSchema.call(hash.merge(id: id)))
end

def to_h
Expand Down
12 changes: 12 additions & 0 deletions lib/arbetsformedlingen/models/position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ def to_h
hash[:salary] = @salary.to_h
hash[:qualifications] = @qualifications.map(&:to_h)
hash[:application_method] = @application_method.to_h
full_address = build_full_address(hash.fetch(:address))
hash[:address][:full_address] = full_address if full_address
hash
end

def build_full_address(address)
return unless address.key?(:street) || address.key?(:zip) || address.key?(:city)

[
address.fetch(:street),
address.fetch(:zip),
address[:city]
].compact.join(', ')
end
end
end
11 changes: 8 additions & 3 deletions lib/arbetsformedlingen/models/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ module Arbetsformedlingen
predicates(Predicates)
end

required(:publish_at_date, :string).filled(:yyyy_mm_dd?)
required(:unpublish_at, :string).filled(:yyyy_mm_dd?)
required(:name, Types::StrippedString).filled
required(:email, Types::StrippedString).filled(:str?, :email?)

optional(:publish_at, :string).filled(:yyyy_mm_dd?)
end

class Publication < Model
def initialize(hash)
data = hash.dup
publish_date = data[:publish_at_date] || Time.now.utc
publish_date = data[:publish_at] || Time.now.utc

data[:publish_at] = publish_date.strftime('%Y-%m-%d')
data[:unpublish_at] = data[:unpublish_at]&.strftime('%Y-%m-%d')

data[:publish_at_date] = publish_date.strftime('%Y-%m-%d')
# TODO: Validate that unpublish_at - publish_at is not greater that 180 days

super(PublicationSchema.call(data))
end
Expand Down
4 changes: 3 additions & 1 deletion lib/arbetsformedlingen/models/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class Schedule < Model

def initialize(hash)
data = hash.dup
data[:position_duration_code] = duration_code(data[:start_date], data[:end_date])
duration_code = duration_code(data[:start_date], data[:end_date])
data[:position_duration_code] = duration_code
data[:full_time] = duration_code == -1
super(ScheduleSchema.call(data))
end

Expand Down
13 changes: 9 additions & 4 deletions lib/arbetsformedlingen/output_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def append_post_detail(node, packet_data)
publication = packet_data.fetch(:publication)

node.PostDetail do |detail|
detail.EndDate { |n| n.Date(publication.fetch(:publish_at_date)) }
if publication[:publish_at]
detail.StartDate { |n| n.Date(publication.fetch(:publish_at)) }
end
detail.EndDate { |n| n.Date(publication.fetch(:unpublish_at)) }

detail.PostedBy do |posted|
posted.Contact do |contact|
Expand Down Expand Up @@ -198,15 +201,17 @@ def append_schedule(node, schedule)
end

def append_delivery_address(node, data)
return node unless data.key?(:full_address) || data.key?(:street)

node.DeliveryAddress do |d_address|
d_address.AddressLine(data.fetch(:full_address))
d_address.StreetName(data.fetch(:street))
d_address.AddressLine(data.fetch(:full_address)) if data.key?(:full_address)
d_address.StreetName(data.fetch(:street)) if data.key?(:street)
end
end

def append_job_position_address(node, address)
node.PostalAddress do |a_node|
a_node.CountryCode(address.fetch(:country_code))
a_node.CountryCode('SE'))
a_node.PostalCode(address.fetch(:zip)) if address.key?(:zip)
a_node.Municipality(address.fetch(:municipality))
append_delivery_address(a_node, address)
Expand Down

0 comments on commit f2e83e8

Please sign in to comment.