Skip to content

Getting started

zverok edited this page Apr 8, 2016 · 2 revisions
require 'reality'
include Reality

Main concept of Reality is entity.

iceland = Entity('Iceland')
# => #<Reality::Entity(Iceland):country>

This statement creates Entity instance and loads its data from data sources. Now, you can easily investigate the object with:

iceland.describe
# Prints: 
#  -----------------------------------
#  #<Reality::Entity(Iceland):country>
#  -----------------------------------
#                 area: #<Reality::Measure(102,775 km²)>
#         calling_code: "+354"
#              capital: #<Reality::Entity?(Reykjavik)>
#            continent: #<Reality::Entity?(Europe)>
#                coord: #<Reality::Geo::Coord(64°49′50″N,17°59′12″W)>
#            iso3_code: "ISL"
#           neighbours: #<Reality::List[Greenland?, Faroe Islands?]>
#     official_website: "http://www.iceland.is/"

# prints much more, in fact! just showing some bits

All entity properties are available through methods:

iceland.capital
# => #<Reality::Entity?(Reykjavik)>
iceland.capital.describe
# Prints: 
#  -----------------------------
#  #<Reality::Entity(Reykjavík)>
#  -----------------------------
#                coord: #<Reality::Geo::Coord(64°9′0″N,21°52′60″W)>
#              country: #<Reality::Entity?(Iceland)>
#   head_of_government: #<Reality::Entity?(Dagur B. Eggertsson)>
#           located_in: #<Reality::Entity?(Capital Region)>
#     official_website: "http://www.rvk.is"
#            tz_offset: nil
# => nil
iceland.capital.head_of_government.describe
# Prints: 
#  ------------------------------------------------
#  #<Reality::Entity(Dagur Bergþóruson Eggertsson)>
#  ------------------------------------------------
#      birthday: Mon, 19 Jun 1972
#   citizenship: #<Reality::Entity?(Iceland)>
#    given_name: "Dagur"
#   occupations: ["politician"]
#      position: "Mayor of Reykjavík"
#           sex: "male"

Next: more about Entity and its properties.