Class: JsonStatham::Schema
- Inherits:
-
Object
- Object
- JsonStatham::Schema
- Defined in:
- lib/json_statham/schema.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
- #array_map ⇒ Object
- #call ⇒ Object
-
#initialize(object) ⇒ Schema
constructor
A new instance of Schema.
- #transformed_hash ⇒ Object
Constructor Details
#initialize(object) ⇒ Schema
Returns a new instance of Schema.
11 12 13 |
# File 'lib/json_statham/schema.rb', line 11 def initialize(object) @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/json_statham/schema.rb', line 5 def object @object end |
Class Method Details
.call(object) ⇒ Object
7 8 9 |
# File 'lib/json_statham/schema.rb', line 7 def self.call(object) new(object).call end |
Instance Method Details
#array_map ⇒ Object
30 31 32 33 34 |
# File 'lib/json_statham/schema.rb', line 30 def array_map return unless object.is_a?(Array) object.map { |obj| self.class.call(obj) } end |
#call ⇒ Object
15 16 17 18 19 20 |
# File 'lib/json_statham/schema.rb', line 15 def call return array_map if object.is_a?(Array) return transformed_hash if object.is_a?(Hash) object.class.name.downcase end |
#transformed_hash ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/json_statham/schema.rb', line 22 def transformed_hash return unless object.is_a?(Hash) object .transform_keys(&:to_s) .transform_values { |obj| self.class.call(obj) } end |