Build Your Own World Almanac in 10 Lines of Script (w/ the Factbook Library) in Ruby

39 views
Skip to first unread message

Gerald Bauer

unread,
Nov 9, 2015, 9:29:32 AM11/9/15
to openmundi
Hello,

The lastest (and greatest) version of the factbook library [1],
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 subscripts/100, religions, ethnic
groups, languages,and so on. See ALMANAC.md [2] as an example.

How to build your 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 [3] 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 render / 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 [4] as an example. Cheers.


PS: Bonus Question - Name the largest country in Africa:

A) Nigeria
B) South Africa
C) Kongo
D) Algeria Anyone?

[1] github.com/worlddb/factbook
[2] github.com/factbook/factbook.json/blob/master/ALMANAC.md
[3] github.com/factbook/factbook.json
[4] github.com/worlddb/factbook/blob/master/script/almanac.rb
Reply all
Reply to author
Forward
0 new messages