Sha256: 29c48b0d65e80f8f1577e8528aeaf5be3e28adb32c107033efb8250383042f13

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module WhosGotDirt
  module Responses
    module List
      # Converts lists from the OpenCorporates API to Popolo format.
      #
      # @see http://api.littlesis.org/documentation
      class LittleSis < Helpers::LittleSisHelper
        @count_field = 'Lists'

        @template = {
          '@type' => 'List',
          'name' => '/name',
          'description' => '/description',
          'number_of_items' => integer_formatter('number_of_items', '/num_entities'),
          'item_list_order' => lambda{|data|
            v = JsonPointer.new(data, '/is_ranked').value
            if v == '1'
              v = 'ascending'
            else
              v = 'unordered'
            end
            ['item_list_order', v]
          },
          'identifiers' => [{
            'identifier' => '/id',
            'scheme' => 'LittleSis',
          }],
          'updated_at' => date_formatter('updated_at', '/updated_at'),
        }

        # Transforms the parsed response body into results.
        #
        # @return [Array<Hash>] the results
        def to_a
          parsed_body['Data']['Lists']['List'].map do |data|
            Result.new('List', renderer.result(data), self).finalize!
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.3 lib/whos_got_dirt/responses/list/little_sis.rb