Skip to content

Commit

Permalink
🐛 Fix prerequisite handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Nov 29, 2023
1 parent 6f3c0a8 commit 8b3b2e9
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 117 deletions.
34 changes: 34 additions & 0 deletions src/main/java/dev/ebullient/convert/tools/JsonTextConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ default JsonNode createNode(String source) {
}
}

default boolean isArrayNode(JsonNode node) {
return node != null && node.isArray();
}

default boolean isObjectNode(JsonNode node) {
return node != null && node.isObject();
}

default JsonNode objectIntersect(JsonNode a, JsonNode b) {
if (a.equals(b)) {
return a;
}
ObjectNode x = Tui.MAPPER.createObjectNode();
for (String k : iterableFieldNames(a)) {
if (a.get(k).equals(b.get(k))) {
x.set(k, a.get(k));
} else if (isObjectNode(a.get(k)) && isObjectNode(b.get(k))) {
x.set(k, objectIntersect(a.get(k), b.get(k)));
}
}
return x;
}

default boolean isPresent(String s) {
return s != null && !s.isBlank();
}

default String formatDice(String diceRoll) {
// needs to be escaped: \\ to escape the \\ so it is preserved in the output
String avg = parseState().inMarkdownTable() ? "\\\\|avg" : "|avg";
Expand Down Expand Up @@ -134,6 +161,9 @@ default Iterable<JsonNode> iterableElements(JsonNode source) {
if (source == null) {
return List.of();
}
if (!source.isArray()) {
return List.of(source);
}
return source::elements;
}

Expand Down Expand Up @@ -170,6 +200,10 @@ default String joinConjunct(String lastJoiner, List<String> list) {
return joinConjunct(list, ", ", lastJoiner, false);
}

default String joinConjunct(String joiner, String lastJoiner, List<String> list) {
return joinConjunct(list, joiner, lastJoiner, false);
}

default String joinConjunct(List<String> list, String joiner, String lastJoiner, boolean nonOxford) {
if (list == null || list.isEmpty()) {
return "";
Expand Down
Loading

0 comments on commit 8b3b2e9

Please sign in to comment.