 ###
 TODO: comment
 
-class: ([String [, String]]) -> AttributeTemplateParser
+class: ([Options]) -> AttributeTemplateParser
     @param 1
-    @param 2
 
     build: (Array(DOMElement)) -> (Period) -> void
         @param 1
         @return
+Options:
+    displayAttribute: String
+    hidableAttribute: String
+    zeroPadOverrides: String => bool
 ###
+        
+# Array(Array(T)) -> Array(T)
+flatten = (outer) ->
+    out = [] #Array(T)
+    #out <- elem for outer(inner(elem))
+    out.push(elem) for elem in inner for inner in outer
+    out
+
+cloneObj = (original) ->
+    ret = {}
+    for key, val of original
+        ret[key] = val
+    ret
+
+zeroPad = (num) -> if num < 10 then "0#{num}" else "#{num}"
+noopZeroPad = (num) -> "#{num}"
 
 class AttributeTemplateParser
     DOM_DISPLAY_ATTRIBUTE = "tminus-unit"
     DOM_HIDABLE_ATTRIBUTE = "tminus-hide-if-zero"
     
     # Period.getUnit keys -> shouldZeroPad
+    # Uses a dictionary instead of an object because the names have semantic value
     RECOGNIZED_KEYS = {}
     RECOGNIZED_KEYS["s"] = true
     RECOGNIZED_KEYS["S"] = true

        else
            false
    
    build: (rootElements) ->
        displayAttributeKey = "[data-#{@displayAttribute}]" #Cache key because function scope messes with it
        displayElements = flatten (element.querySelectorAll(displayAttributeKey) for element in rootElements)
        hidableAttributeKey = "[data-#{@hidableAttribute}]" #Cache key because function scope messes with it
        hidableElements = flatten (element.querySelectorAll(hidableAttributeKey) for element in rootElements)
        
        #Create updaters for each key, filter out the keys without updaters and flatmap to a single array
        updaters = (@createUpdater key, shouldZeroPad, displayElements, hidableElements for key, shouldZeroPad of RECOGNIZED_KEYS).filter (x) -> x isnt false
        (period) -> 
            updater(period) for updater in updaters
            true

    RECOGNIZED_KEYS["H"] = false
    RECOGNIZED_KEYS["d"] = false
        
    createUpdater = (key, shouldZeroPad, filteredDisplay, filteredHidable) ->
        localZeroPad = if shouldZeroPad then zeroPad else noopZeroPad
        
        previousValue = Number.NaN
