Added device struct Liquid attributes

Necessary to generate attributes for Liquid templates. Will soon be used during extension import of TRMNL Recipes in order to supply device information.

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-08-11 11:20:07 -06:00
parent ee557c2c8b
commit 62610555bf
2 changed files with 15 additions and 0 deletions
+5
View File
@@ -1,11 +1,14 @@
# frozen_string_literal: true
require "core"
require "refinements/hash"
module Terminus
module Structs
# The device struct.
class Device < DB::Struct
using Refinements::Hash
def asleep? at = Time.now, type: Sequel::SQLTime
return false unless sleep_start_at && sleep_stop_at
@@ -33,6 +36,8 @@ module Terminus
}
end
def liquid_attributes = {id:, battery_percentage:, wifi_percentage:}.stringify_keys!
def slug
return Core::EMPTY_STRING unless mac_address
+10
View File
@@ -147,6 +147,16 @@ RSpec.describe Terminus::Structs::Device, :db do
end
end
describe "#liquid_attributes" do
it "answers translation" do
expect(device.liquid_attributes).to eq(
"id" => device.id,
"battery_percentage" => 70,
"wifi_percentage" => 90
)
end
end
describe "#slug" do
it "answers string with no colons" do
expect(device.slug).to eq("AABBCC112233")