Sha256: 7b4955a7a2b042ef5af14adb18351746d8dca32933c46858076019023c49f87b

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Arbetsformedlingen
  module API
    module Values
      SoklistaPage = KeyStruct.new(
        :list_name,
        :total_ads,
        :total_vacancies,
        :data,
        :raw_data,
        :response
      )
      class SoklistaPage
        include Enumerable

        def each(&block)
          data.each(&block)
        end

        def to_h
          hash = super.to_h
          hash.delete(:response) # don't return the raw response object
          hash[:data].map!(&:to_h)
          hash
        end

        def method_missing(method_name, *arguments, &block)
          if response.respond_to?(method_name)
            response.public_send(method_name, *arguments, &block)
          else
            super
          end
        end

        def respond_to_missing?(method_name, include_private = false)
          response.respond_to?(method_name) || super
        end
      end

      SoklistaResult = KeyStruct.new(
        :id,
        :name,
        :total_ads,
        :total_vacancies
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arbetsformedlingen-0.7.0 lib/arbetsformedlingen/api/values/soklista_values.rb
arbetsformedlingen-0.6.0 lib/arbetsformedlingen/api/values/soklista_values.rb