Sha256: 49d25325e6acfdf91e1fc6f5c80ebb0aef039fd1f51c4b2f01f77553d54915c6

Contents?: true

Size: 654 Bytes

Versions: 1

Compression:

Stored size: 654 Bytes

Contents

require 'hashie'
require 'multi_json'
require_relative 'base'
require_relative 'collection'
require_relative 'success'

module Feedlr
  # The generalized pseudo-object that is returned for all query
  # requests.
  # http://martinfowler.com/eaaCatalog/dataMapper.html
  class Mapper
    # Build the proper object depending on the response
    # @return [Feedlr::Base, Feedlr::Success, Feedlr::Collection]
    def self.build(data)
      case data
      when Hash
        (data.size > 0) ? Feedlr::Base.new(data) : Feedlr::Success.new
      when Array
        Feedlr::Collection.new(data)
      else
        Feedlr::Success.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
feedlr-0.1.0 lib/feedlr/mapper.rb