Build Your Own World Almanac in 50 Lines of Ruby (w/ the factbook Gem)
Hello, The lastest (and greatest) version of the factbook library - that is, v1.1.1 - now includes a new almanac class that lets you build your own world almanac e.g. listing all the world’s 260+ countries and territories with capitals, population, internet users, mobile telephone subscriptions/100, religions, ethnic groups, languages, and so on. See ALMANAC.md as an example. How to build your very own in three steps:
Step 1: Get a copy of the factbook.json archive
Use git clone (or unpack the zip archive) using factbook/factbook.json github repo.
Step 2: Load the profiles using the Almanac class
almanac = Factbook::Almanac.from_json( Factbook.codes.countries, json_dir: './factbook.json' )
Step 3: Use your template of choice and build the Almanac text corpus
TEMPLATE = <<EOS
### <%= page.name %>
<%= page.capital %> • <%= page.area %> • pop. <%= page.population %>
...
EOS
puts almanac.render( TEMPLATE )
That’s it. See the scripts/almanac.rb as an example. Cheers.
Post a comment