Sha256: f9d276a2e71544e9e6af4d23f70cf9dc36d5573153a3b5c489066e588a925296

Contents?: true

Size: 546 Bytes

Versions: 1

Compression:

Stored size: 546 Bytes

Contents

module Transcriber
  class Resource
    class Embeddable
      module Response
        def to_resource(parent)
          return {} unless visible?(parent)
          resource = nil

          if embedded = parent.__send__(name)
            resource = raw? ? embedded : resourcify(embedded)
          elsif many?
            resource = []
          end

          {name => resource}
        end

        private

        def resourcify(embedded)
          one? ? embedded.resource : embedded.map(&:resource)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
transcriber-0.0.26 lib/transcriber/resource/key/embeddable/response.rb