Class: PetstoreApiClient::Models::NamedEntity
- Defined in:
- lib/petstore_api_client/models/named_entity.rb
Overview
Base class for simple entities with just ID and name Used by Category and Tag models to eliminate duplication
This is an example of the DRY principle - both Category and Tag were 100% identical, so we extracted their common behavior here.
Class Method Summary collapse
-
.from_response(data) ⇒ Object
Create from API response data Handles both string and symbol keys.
Instance Method Summary collapse
-
#to_h ⇒ Object
Override to_h to use symbol keys (API expects this format).
Class Method Details
.from_response(data) ⇒ Object
Create from API response data Handles both string and symbol keys
26 27 28 29 30 31 32 33 |
# File 'lib/petstore_api_client/models/named_entity.rb', line 26 def self.from_response(data) return nil if data.nil? new( id: extract_field(data, :id), name: extract_field(data, :name) ) end |
Instance Method Details
#to_h ⇒ Object
Override to_h to use symbol keys (API expects this format)
17 18 19 20 21 22 |
# File 'lib/petstore_api_client/models/named_entity.rb', line 17 def to_h { id: id, name: name }.compact end |