Sha256: 3fc129f7301fb7a3a6f65b009cf65c7adbb50dd2cd391b1d4b7f78acb47fcad3

Contents?: true

Size: 658 Bytes

Versions: 1

Compression:

Stored size: 658 Bytes

Contents

module Barchart
  class Resource

    def self.initialize_from_array_response(resource_class, response)
      JSON.parse(response.body).map do |resource_json|
        resource_class.new(resource_json)
      end
    end

    attr_reader :response_json, :struct

    def initialize(response)
      @response_json = response
      @struct = RecursiveOpenStruct.new(@response_json, {recurse_over_arrays: true})
    end

    def as_json(options = {})
      @response_json
    end

    def method_missing(name, *args)
      @struct[name.to_sym]
    end

    def inspect
      @struct.inspect.gsub(/#<RecursiveOpenStruct/,"#<#{self.class.name}")
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
barchart-0.0.1 lib/barchart/resources/resource.rb