Added recipe author model

Necessary to model a recipe author. A `Struct` is used because some keys are optional. This injects the `LocaleReducer` in order to convert all description locales to a hash for quick lookup rather than use the redundant keys provided by the API. Will soon be used by the recipe model (soon to be added).

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-01-15 09:17:29 -07:00
parent 8afdadbe57
commit d4209e5f01
2 changed files with 59 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
# frozen_string_literal: true
module TRMNL
module API
module Models
module Recipes
# Models the author of the API response.
Author = Struct.new(
:keyname,
:name,
:field_type,
:category,
:description,
:description_locales,
:email_address,
:learn_more_url,
:github_url,
:youtube_url
) do
def self.for(locale_reducer: LocaleReducer, **attributes)
description_locales = locale_reducer.call attributes
new(description_locales:, **attributes)
end
end
end
end
end
end
@@ -0,0 +1,31 @@
# frozen_string_literal: true
require "spec_helper"
RSpec.describe TRMNL::API::Models::Recipes::Author do
subject(:author) { described_class.new }
describe ".for" do
let :attributes do
{
name: "test",
"description-de": "german",
"description-nl": "dutch",
"description-fr": "french"
}
end
it "transforms description locales to hash by key only" do
expect(described_class.for(**attributes)).to eq(
described_class[
name: "test",
description_locales: {
"de" => "german",
"nl" => "dutch",
"fr" => "french"
}
]
)
end
end
end