Sha256: a653f2430d36fe3e325ba35808f381e40ace6f92bd1453a45bd29a6e1db52f4c

Contents?: true

Size: 662 Bytes

Versions: 3

Compression:

Stored size: 662 Bytes

Contents

# frozen_string_literal: true

module JsonStatham
  class Schema
    attr_reader :object

    def self.call(object)
      new(object).call
    end

    def initialize(object)
      @object = object
    end

    def call
      return array_map if object.is_a?(Array)
      return transformed_hash if object.is_a?(Hash)

      object.class.name.downcase
    end

    def transformed_hash
      return unless object.is_a?(Hash)

      object
        .transform_keys(&:to_s)
        .transform_values { |obj| self.class.call(obj) }
    end

    def array_map
      return unless object.is_a?(Array)

      object.map { |obj| self.class.call(obj) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_statham-0.1.3 lib/json_statham/schema.rb
json_statham-0.1.2 lib/json_statham/schema.rb
json_statham-0.1.0 lib/json_statham/schema.rb