forked from jeremyfsu/hairforecast_rest_api
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JsonFinder get children is now passing it's test
- Loading branch information
Jeremy Walworth
committed
Mar 17, 2013
1 parent
3972f32
commit c8cdee6
Showing
1 changed file
with
11 additions
and
6 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 |
---|---|---|
@@ -1,19 +1,24 @@ | ||
class JsonFinder | ||
|
||
constructor: (json) -> | ||
@json = json | ||
|
||
recurse_children: (name, obj) -> | ||
@json = JSON.parse json | ||
descend: (name, obj) -> | ||
if obj.name == name | ||
return obj.childs | ||
else | ||
obj.childs.every (child) -> | ||
this.recurse_children(name,child) | ||
for i in [0..obj.childs.length - 1] | ||
if typeof(obj.childs[i]) == "string" | ||
break | ||
result = this.descend(name, obj.childs[i]) | ||
if typeof(result) != 'undefined' | ||
return result | ||
|
||
get_attr: (name) -> | ||
"not impleneted yet" | ||
|
||
get_children: (name) -> | ||
return this.recurse_children(name,@json) | ||
return this.descend(name, @json) | ||
|
||
root = exports ? window | ||
root.JsonFinder = JsonFinder |