class Arbetsformedlingen::Position

Public Class Methods

new(attributes:, company:, schedule:, salary:, qualifications:, application_method:) click to toggle source
Calls superclass method Arbetsformedlingen::Model::new
# File lib/arbetsformedlingen/models/position.rb, line 25
def initialize(attributes:, company:, schedule:, salary:, qualifications:, application_method:) # rubocop:disable Metrics/LineLength
  hash = attributes
  @company = company
  @schedule = schedule
  @salary = salary
  @qualifications = qualifications
  @application_method = application_method

  super(PositionSchema.call(hash))
end

Public Instance Methods

build_full_address(address) click to toggle source
# File lib/arbetsformedlingen/models/position.rb, line 48
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
to_h() click to toggle source
Calls superclass method Arbetsformedlingen::Model#to_h
# File lib/arbetsformedlingen/models/position.rb, line 36
def to_h
  hash = super
  hash[:company] = @company.to_h
  hash[:schedule] = @schedule.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