WeatherMunger Kata 3 (String.format-DRY)





0
Date Submitted Fri. Jan. 4th, 2008 5:16 PM
Revision 1 of 1
Helper BerndSchiffer
Tags groovy
Comments 0 comments
WeatherMunger Kata 3 (String.format-DRY)

def number = /\W+(\d+)/
def eintraege = []
new File('weather.dat').text.eachMatch(/(?m)^${number * 3}.*/){ all, tag, max, min ->
        def spread = max.toInteger() - min.toInteger()
        eintraege << [tag:tag, spread:spread, min:min, max:max]
}
eintraege
        .sort{ it.spread }
        .each{
                def format = it.keySet().collect{ format(it) + ':%3s'}.join(' ')
                def values = it.values()*.toString()
                println String.format(format, *values)
        }
       
def format(label) { label[0].toUpperCase() + label[1..-1] }
 

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Votes Down