Skip to content

Commit

Permalink
add tag list.map_get
Browse files Browse the repository at this point in the history
fancy imitation maps!
  • Loading branch information
mcmonkey4eva committed Oct 25, 2014
1 parent 2b61d75 commit 42030c1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -382,6 +382,46 @@ public String getAttribute(Attribute attribute) {
return sub_list.getAttribute(attribute);
}

// <--[tag]
// @attribute <li@list.map_get[<element>]>
// @returns dList
// @description
// Returns the sub-list split by the / symbol's
// value for the matching input element.
// TODO: Clarify
// EG: li@one/a|two/b.map_get[one] returns a.
// -->

if (attribute.startsWith("map_get")
&& attribute.hasContext(1)) {
String input = attribute.getContext(1);
attribute.fulfill(1);


// <--[tag]
// @attribute <li@list.map_get[<element>].split_by[<element>]>
// @returns dList
// @description
// Returns the sub-list split by the given symbol's
// value for the matching input element.
// TODO: Clarify
// EG: li@one/a|two/b.map_get[one] returns a.
// -->

String split = "/";
if (attribute.startsWith("split_by")) {
if (attribute.hasContext(1) && attribute.getContext(1).length() > 0)
split = attribute.getContext(1);
attribute.fulfill(1);
}

for (String item : this) {
String[] strings = item.split(Pattern.quote(split));
if (strings.length > 1 && strings[0].equalsIgnoreCase(input)) {
return new Element(strings[1]).getAttribute(attribute);
}
}
}

// <--[tag]
// @attribute <li@list.comma_separated>
Expand Down

0 comments on commit 42030c1

Please sign in to comment.