Skip to content

Commit

Permalink
feat(geobase): property builder utility #138
Browse files Browse the repository at this point in the history
  • Loading branch information
navispatial committed Aug 5, 2022
1 parent 32fe24d commit a4a10ab
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions dart/geobase/lib/src/utils/property_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2020-2022 Navibyte (https://navibyte.com). All rights reserved.
// Use of this source code is governed by a “BSD-3-Clause”-style license that is
// specified in the LICENSE file.
//
// Docs: https://github.com/navibyte/geospatial

import '/src/vector/content.dart';

/// A builder to create property maps from [PropertyContent] stream.
class PropertyBuilder with PropertyContent {
final Map<String, Object?> _map;

const PropertyBuilder._(this._map);

/// Builds a property map from the content stream provided by [properties].
///
/// Built property objects are sent into the [to] map (that is also returned).
static Map<String, Object?> buildTo(
WriteProperties properties, {
required Map<String, Object?> to,
}) {
final builder = PropertyBuilder._(to);
properties.call(builder);
return to;
}

/// Builds a property map from the content stream provided by [properties].
static Map<String, Object?> buildMap(WriteProperties properties) {
final map = <String, Object?>{};
final builder = PropertyBuilder._(map);
properties.call(builder);
return map;
}

@override
void properties(String name, Map<String, Object?> map) {
_map[name] = map;
}

@override
void property(String name, Object? value) {
_map[name] = value;
}
}

0 comments on commit a4a10ab

Please sign in to comment.