Groovy web console

subscribe to the feed Subscribe
to this
site
Lorem Ipsum (via #groovywebconsole)
tweet this snippet Tweet
this
script

Lorem Ipsum

Published 4 years ago by Søren Berg Glasius with tags xml feed lorem ipsum
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/**
 * Use the lipsum generator to generate Lorem Ipsum dummy paragraphs / words / bytes.
 *
 * Lorem Ipsum courtesy of www.lipsum.com by James Wilson
 *
 * @param what in ['paras','words','bytes'], default: 'paras'
 * @param amount of paras/words/bytes, default: 2 (for words minimum is 5, for bytes it is 27)
 * @param start always start with 'Lorem Ipsum', default = true
 **/
def lipsum = { what = "paras", amount = 2, start = true ->
    def text = new URL("http://www.lipsum.com/feed/xml?what=$what&amount=$amount&start=${start?'yes':'no'}").text

    def feed = new XmlSlurper().parseText(text)
    
    feed.lipsum.text()
}

assert lipsum() instanceof String
assert lipsum().startsWith('Lorem ipsum')
assert lipsum().split(/\n/).size() == 2
assert lipsum('paras', 10).split(/\n/).size() == 10
assert lipsum(start: false).startsWith('Lorem ipsum')
assert lipsum('words').split(/ /).size() == 5
assert lipsum('bytes').size() == 27
assert lipsum('words',10).split(/ /).size() == 10