Sha256: 2225a507e52405a7ca640d63fc95a03ca2979d92b75fafec7dd2e701c8c3ddf1

Contents?: true

Size: 624 Bytes

Versions: 1

Compression:

Stored size: 624 Bytes

Contents

require 'json'

module Bling
  module API
    class Parser

      def initialize(text, klass_name)
        @text, @klass_name = text, klass_name
      end

      def result
        raw_response = JSON.parse(@text)
        Translator.translate_hash(raw_response, to: :en)
      end

      def records
        raw_records = result[:return][plural_klass_name]
        return [] if raw_records.nil?
        raw_records.each_with_object([]) { |record, result| result << Record.new(record[@klass_name]) }
      end

      private

      def plural_klass_name
        @klass_name.to_s.pluralize.to_sym
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bling-ruby-api-0.0.1 lib/bling/api/parser.rb