-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(geobase): property builder utility #138
- Loading branch information
1 parent
32fe24d
commit a4a10ab
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |