convert provider -> Provider

This commit is contained in:
Emil Lerch 2025-12-18 15:06:44 -08:00
parent 66d1e7fa79
commit 448c49ae79
Signed by: lobo
GPG key ID: A7B62D657EF764F8
5 changed files with 30 additions and 30 deletions

View file

@ -1,7 +1,7 @@
const std = @import("std");
const httpz = @import("httpz");
const Cache = @import("../cache/Cache.zig");
const WeatherProvider = @import("../weather/provider.zig").WeatherProvider;
const WeatherProvider = @import("../weather/Provider.zig");
const Resolver = @import("../location/resolver.zig").Resolver;
const Location = @import("../location/resolver.zig").Location;
const QueryParams = @import("query.zig").QueryParams;

View file

@ -1,5 +1,5 @@
const std = @import("std");
const weather_provider = @import("provider.zig");
const WeatherProvider = @import("Provider.zig");
const types = @import("types.zig");
const MetNo = @This();
@ -12,7 +12,7 @@ pub fn init(allocator: std.mem.Allocator) !MetNo {
};
}
pub fn provider(self: *MetNo) weather_provider.WeatherProvider {
pub fn provider(self: *MetNo) WeatherProvider {
return .{
.ptr = self,
.vtable = &.{
@ -107,11 +107,11 @@ fn parseMetNoResponse(allocator: std.mem.Allocator, location: []const u8, json:
const instant = data.object.get("instant") orelse return error.InvalidResponse;
const details = instant.object.get("details") orelse return error.InvalidResponse;
const temp_c = @as(f32, @floatCast(details.object.get("air_temperature").?.float));
const humidity = @as(u8, @intFromFloat(details.object.get("relative_humidity").?.float));
const temp_c: f32 = @floatCast(details.object.get("air_temperature").?.float);
const humidity: u8 = @intFromFloat(details.object.get("relative_humidity").?.float);
const wind_speed_ms = details.object.get("wind_speed").?.float;
const wind_kph = @as(f32, @floatCast(wind_speed_ms * 3.6));
const pressure_mb = @as(f32, @floatCast(details.object.get("air_pressure_at_sea_level").?.float));
const wind_kph: f32 = @floatCast(wind_speed_ms * 3.6);
const pressure_mb: f32 = @floatCast(details.object.get("air_pressure_at_sea_level").?.float);
// Get weather symbol
const next_1h = data.object.get("next_1_hours");
@ -173,7 +173,7 @@ fn symbolCodeToCondition(symbol: []const u8) []const u8 {
fn degreeToDirection(deg: f32) []const u8 {
const normalized = @mod(deg + 22.5, 360.0);
const idx = @as(usize, @intFromFloat(normalized / 45.0));
const idx: usize = @intFromFloat(normalized / 45.0);
const directions = [_][]const u8{ "N", "NE", "E", "SE", "S", "SW", "W", "NW" };
return directions[@min(idx, 7)];
}

View file

@ -1,5 +1,5 @@
const std = @import("std");
const weather_provider = @import("provider.zig");
const WeatherProvider = @import("Provider.zig");
const types = @import("types.zig");
const Mock = @This();
@ -14,7 +14,7 @@ pub fn init(allocator: std.mem.Allocator) !Mock {
};
}
pub fn provider(self: *Mock) weather_provider.WeatherProvider {
pub fn provider(self: *Mock) WeatherProvider {
return .{
.ptr = self,
.vtable = &.{

20
src/weather/Provider.zig Normal file
View file

@ -0,0 +1,20 @@
const std = @import("std");
const types = @import("types.zig");
const WeatherProvider = @This();
ptr: *anyopaque,
vtable: *const VTable,
pub const VTable = struct {
fetch: *const fn (ptr: *anyopaque, allocator: std.mem.Allocator, location: []const u8) anyerror!types.WeatherData,
deinit: *const fn (ptr: *anyopaque) void,
};
pub fn fetch(self: WeatherProvider, allocator: std.mem.Allocator, location: []const u8) !types.WeatherData {
return self.vtable.fetch(self.ptr, allocator, location);
}
pub fn deinit(self: WeatherProvider) void {
self.vtable.deinit(self.ptr);
}

View file

@ -1,20 +0,0 @@
const std = @import("std");
const types = @import("types.zig");
pub const WeatherProvider = struct {
ptr: *anyopaque,
vtable: *const VTable,
pub const VTable = struct {
fetch: *const fn (ptr: *anyopaque, allocator: std.mem.Allocator, location: []const u8) anyerror!types.WeatherData,
deinit: *const fn (ptr: *anyopaque) void,
};
pub fn fetch(self: WeatherProvider, allocator: std.mem.Allocator, location: []const u8) !types.WeatherData {
return self.vtable.fetch(self.ptr, allocator, location);
}
pub fn deinit(self: WeatherProvider) void {
self.vtable.deinit(self.ptr);
}
};