reality 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81bd37c8f48b943d3f21927ba08a6632c3646e29
4
- data.tar.gz: 60515a620873fe07de08f2de446148003f95152b
3
+ metadata.gz: 83f98ac0ff14263d69ba4a5b081f819c9f354d44
4
+ data.tar.gz: d1d195e02fcd9399846dd7f0294d29d5839cdfc9
5
5
  SHA512:
6
- metadata.gz: c8ec19350cc2616ce97065ea6651c739936def8b4e3e9014e4afed52fe3dec35f265bc5c6fc03746fbb7c31c8c8f6134ff30ce4501593c73a375ce9f3d9fcbf2
7
- data.tar.gz: 06b7ab6e795fd71ffdc7983a279b2c3bb3e7caf2829593eda917820bba32ec6d125e9b0c4b844aa545f9d86cb550c81d8b189389c6606c79fa49dd89b53c1124
6
+ metadata.gz: 070c509c6bd1bdb255a076e3cc14d6b19b757c0dfccd9350e75eab1e3a24ad4708f5a62b31fc178dd6303fdb39b447c0eb799102e528e9bb78eea0dbcf8b7646
7
+ data.tar.gz: d36906f1e461d19072ed1b07fd4ea7f476b0559a4788880e306b5a849cd6c898abe6b0af55342377235cc17cb0419ad20fbdcd3958feb0e5f7e95d8c7cdb6680
@@ -0,0 +1,2 @@
1
+ --markup=markdown
2
+ --no-private
@@ -0,0 +1,20 @@
1
+ ## 0.0.4 - 2016-04-18
2
+
3
+ * Economic indicators from Quandl;
4
+ * Fallback to search in Wikidata only, if there is no Wikipedia page;
5
+ * Add `reality` binary for using from command line;
6
+ * Several small and not-so-small refactorings (especially of Wikidata
7
+ module, which was a complete mess);
8
+ * Add `Entity#to_h` (with only core types, so entities are JSON-able now!);
9
+ * Enchance of `Geo::Coord` class with several new features;
10
+ * Allow sparse `Reality::List`, with `nil`s alongside with entities,
11
+ useful for things like `cities_list.map(&:head_of_government).load!` --
12
+ not for all cities head of government is known, but the code will work
13
+ nevertheless;
14
+ * More useful Wikidata predicates;
15
+ * Optional `Reality::Names` module, allowing code like `Argentina.capital`;
16
+ * Some docs -- both YARD and Wiki.
17
+
18
+ ## 0.0.3 - 2016-03-02
19
+
20
+ First really public release
data/README.md CHANGED
@@ -2,12 +2,31 @@ Reality
2
2
  =======
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/reality.svg)](http://badge.fury.io/rb/reality)
5
+ [![Build Status](https://travis-ci.org/molybdenum-99/reality.svg?branch=master)](https://travis-ci.org/molybdenum-99/reality)
5
6
  [![Join the chat at https://gitter.im/molybdenum-99/reality](https://badges.gitter.im/molybdenum-99/reality.svg)](https://gitter.im/molybdenum-99/reality?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
7
 
7
8
  **Reality** is your quick access point to almost any entity existing in
8
9
  real world (and described in Wikipedia). Its goal is to make the world
9
10
  inspectable and computable.
10
11
 
12
+ ## Table Of Contents
13
+
14
+ * [Showcase](#showcase)
15
+ * [Is it real? Is it really working?.. But how?](#is-it-real-is-it-really-working-but-how)
16
+ * [Why/when do I need this?..](#whywhen-do-i-need-this)
17
+ * [Uhm, ok. How to use it?](#uhm-ok-how-to-use-it)
18
+ * [...from your code](#from-your-code)
19
+ * [...from command-line](#from-command-line)
20
+ * [...from interactive console](#from-interactive-console)
21
+ * [Good. What next?..](#good-what-next)
22
+ * [Docs](#docs)
23
+ * [Want to help?](#want-to-help)
24
+ * [Compatibility](#compatibility)
25
+ * [Credits](#credits)
26
+ * [License](#license)
27
+
28
+ ## Showcase
29
+
11
30
  ```ruby
12
31
  # Like this
13
32
  require 'reality'
@@ -50,18 +69,14 @@ beatles.select(&:alive?).map{|beatle| beatle.albums && beatle.albums.last}
50
69
  # => [#<Reality::Entity?(New (album))>, #<Reality::Entity?(Old Wave)>, nil]
51
70
 
52
71
  # and stuff
53
- titanic = Entity('Titanic (1997 film)')
54
- titanic.actors.each do |actor|
55
- puts "#{ actor.name }: #{ actor.age_at(titanic.published_at) }"
72
+ t2 = Entity('Terminator 2')
73
+ t2.actors.each do |actor|
74
+ puts "#{ actor.name }: #{ actor.age_at(t2.published_at) }"
56
75
  end
57
- # Frances Fisher: 45
58
- # Leonardo DiCaprio: 22
59
- # Danny Nucci: 29
60
- # Bill Paxton: 42
61
- # Gloria Stuart: 87
62
- # Kate Winslet: 22
63
- # Billy Zane: 31
64
- # ......
76
+ # Edward Furlong: 13
77
+ # Arnold Schwarzenegger: 43
78
+ # Linda Hamilton: 34
79
+ # Robert Patrick: 32
65
80
  ```
66
81
 
67
82
  ## Is it real? Is it really working?.. But how?
@@ -71,432 +86,93 @@ are working. And almost _any_ thing which Wikipedia knows about, can be
71
86
  loaded through **Reality**, and somehow inspected and used and navigated
72
87
  to next entities and measured and ...
73
88
 
74
- For any entity (or list of entities) you request, it will do:
75
- * query English Wikipedia for this entity by name;
76
- * gather data from Wikipedia **and** Wikidata, by several parsing rules
77
- (the list of them is growing every day);
78
- * present you with `Entity` object with ton of useful methods.
79
-
80
- Above this core functionality, **Reality** also does:
81
- * allow you to navigate through entity and linked entities and lists of
82
- them;
83
- * provide some (simple, but pretty looking) value classes like "amount
84
- with units" (see distances and populations above), "geo coordinates",
85
- "timezone offset" and so on;
86
- * mix some other services (few for now, dozens in future) into those
87
- value types, like `Geo::Coord#weather` through OpenWeatherMap and
88
- so on.
89
-
90
- Eventually, **Reality**, following its pretentious name, plans to interconnect
91
- multiple open data sources (all of them!) into easily navigable and usable
92
- graph of Ruby objects. Or something like that.
89
+ Read more at ["How it works"](https://github.com/molybdenum-99/reality/wiki/How-it-works)
90
+ page in our wiki. It's complicated, yet quite interesting.
93
91
 
94
92
  ## Why/when do I need this?..
95
93
 
96
- Let's start from when you _don't_ need this.
97
-
98
- Reality is not incredibly precise and realiable: for example, as you can
99
- see in first example above, it lists only top cities of country, not all
100
- of them (in fact, it is contents of Wikipedia page "List of cities in
101
- %countryname%"). The data is only as good as data in Wikipedia/Wikidata
102
- **and** our parsers/processors for this data. So, don't try to use
103
- it for really precise scientific computations or really important business
104
- tasks.
105
-
106
- But! Data there is, and already a lot of it, and it will be a lot _moar_
107
- in near future. So, feel free and happy to use Reality for:
108
- * teaching Ruby and data processing on _real and actual_ data;
109
- * use interesting data for experiments, quick scripts and insights about
110
- errrm reality;
111
- * demonstrating some tools for data processing and/or visualisation on
112
- variative and intersting examples;
113
- * initial seeding of development databases with countries, cities, genres,
114
- dates, coordinates and so on;
115
- * ...your option?..
94
+ * Demos and experiments;
95
+ * Enrichement of existing data;
96
+ * Teaching Ruby and data processing on realistic data...
97
+
98
+ ...and [more](https://github.com/molybdenum-99/reality/wiki/Applications).
116
99
 
117
100
  ## Uhm, ok. How to use it?
118
101
 
119
102
  First, install the gem as usual (it is on rubygems, and named "reality"),
120
103
  using Gemfile/`bundle install` or `gem install reality`.
121
104
 
122
- Second, `require "reality"` or use interactive console with the same name.
123
-
124
- Now, to Reality concepts.
125
-
126
- ### Entity
127
-
128
- Now you can use `Reality::Entity`, which is core concept:
129
-
130
- ```ruby
131
- ar = Reality::Entity('Argentina')
132
- # => #<Reality::Entity(Argentina):country>
133
-
134
- ar.describe # shows all fields entity have
135
- # -------------------------------------
136
- # #<Reality::Entity(Argentina):country>
137
- # -------------------------------------
138
- # adm_divisions: #<Reality::List[Buenos Aires?, Buenos Aires Province?, Catamarca Province?, Chaco Province?, Corrientes?, Córdoba Province?, Formosa Province?, Entre Ríos Provinces?, Jujuy Province?, La Pampa Province?, La Rioja Province?, Mendoza Province?, Misiones Province?, Neuquén Province?, Río Negro Province?, Salta Province?, San Juan Province?, San Luis Province?, Santa Cruz Province?, Santa Fe Province?, Santiago del Estero Province?, Tucumán Province?, Tierra del Fuego Province?]>
139
- # area: #<Reality::Measure(2,780,400 km²)>
140
- # calling_code: "+54"
141
- # capital: #<Reality::Entity?(Buenos Aires)>
142
- # continent: #<Reality::Entity?(South America)>
143
- # coord: #<Reality::Geo::Coord(34°0′0″S,64°0′0″W)>
144
- # country: #<Reality::Entity?(Argentina)>
145
- # created_at: #<Date: 1816-01-01>
146
- # currency: #<Reality::Entity?(peso)>
147
- # gdp_nominal: #<Reality::Measure(537,659,972,702 $)>
148
- # gdp_ppp: #<Reality::Measure(964,279,000,000 $)>
149
- # head_of_state: #<Reality::Entity?(Mauricio Macri)>
150
- # highest_point: #<Reality::Entity?(Aconcagua)>
151
- # iso2_code: "AR"
152
- # iso3_code: "ARG"
153
- # long_name: "Argentine Republic"
154
- # neighbours: #<Reality::List[Uruguay?, Brazil?, Chile?, Paraguay?, Bolivia?]>
155
- # organizations: #<Reality::List[United Nations?, Union of South American Nations?, Mercosur?, World Trade Organization?, G-20 major economies?, Central American Bank for Economic Integration?, International Bank for Reconstruction and Development?, African Development Bank?, Andean Community of Nations?, International Finance Corporation?, Australia Group?, International Development Association?, International Centre for Settlement of Investment Disputes?, Multilateral Investment Guarantee Agency?, Agency for the Prohibition of Nuclear Weapons in Latin America and the Caribbean?]>
156
- # part_of: #<Reality::List[Latin America?]>
157
- # population: #<Reality::Measure(43,417,000 person)>
158
- # tld: ".ar"
159
- # tz_offset: #<Reality::TZOffset(UTC-03:00)>
160
-
161
- # all those fields are exposed as methods:
162
- p ar.population
163
- # => #<Reality::Measure(43,417,000 person)>
164
-
165
- # those which are entities could be navigated further:
166
- ar.capital.describe
167
- # -------------------------------------
168
- # #<Reality::Entity(Buenos Aires):city>
169
- # -------------------------------------
170
- # adm_divisions: #<Reality::List[Villa Devoto?, Agronomía?, "Retiro, Buenos Aires"?, "Caballito, Buenos Aires"?, "Chacarita, Buenos Aires"?, Parque Avellaneda?, "Villa Real, Buenos Aires"?, Flores?, Vélez Sársfield?, "Versalles, Buenos Aires"?, "Saavedra, Buenos Aires"?, "Barracas manda , Buenos Aires"?, La Boca?, Villa Lugano?, Villa del Parque?, Villa Luro?, Puerto Madero?, Balvanera?, Belgrano?, Boedo?, "Recoleta, Buenos Aires"?, Palermo?, Villa General Mitre?, Villa Riachuelo?, Villa Pueyrredón?, "San Telmo, Buenos Aires"?, Villa Urquiza?, Villa Santa Rita?, Villa Ortúzar?, "Monserrat, Buenos Aires"?, "Coghlan, Buenos Aires"?, Colegiales?, Parque Chacabuco?, Mataderos?, Constitución?, "Floresta, Buenos Aires"?, Villa Crespo?, Villa Soldati?, "La Paternal, Buenos Aires"?, Liniers?, Monte Castro?, Nueva Pompeya?, San Nicolás?, "Núñez, Buenos Aires"?, Parque Chas?, Parque Patricios?, San Cristóbal?, "Almagro, Buenos Aires"?]>
171
- # area: #<Reality::Measure(203 km²)>
172
- # coord: #<Reality::Geo::Coord(34°35′58″S,58°22′54″W)>
173
- # country: #<Reality::Entity?(Argentina)>
174
- # created_at: #<Date: 1580-06-21>
175
- # elevation: #<Reality::Measure(25 m)>
176
- # long_name: "Autonomous City of Buenos Aires"
177
- # neighbours: #<Reality::List[Buenos Aires Province?]>
178
- # population: #<Reality::Measure(2,890,151 person)>
179
- # population_metro: #<Reality::Measure(12,741,364 person)>
180
- # tz_offset: #<Reality::TZOffset(UTC-03:00)>
181
- ```
182
-
183
- #### Entity loading
184
-
185
- When you see something like
186
- `#<Reality::Entity?(Mauricio Macri)>` it means "not loaded entity" (like
187
- link or reference). Entity can be loaded explicitly via `load!` method,
188
- or implicitly on `method_missing` or `describe` call.
189
-
190
- ```ruby
191
- ar.head_of_state
192
- # => #<Reality::Entity?(Mauricio Macri)>
193
- ar.head_of_state.loaded?
194
- # => false
195
- ar.head_of_state.describe
196
- # ----------------------------------
197
- # #<Reality::Entity(Mauricio Macri)>
198
- # ----------------------------------
199
- # birth_place: #<Reality::Entity?(Tandil)>
200
- # birthday: #<Date: 1959-02-08>
201
- # citizenship: #<Reality::Entity?(Argentina)>
202
- # father: #<Reality::Entity?(Francisco Macri)>
203
- # given_name: "Mauricio"
204
- # occupations: ["businessperson", "politician", "civil engineer"]
205
- # position: "President of Argentina"
206
- # sex: "male"
207
- # spouse: #<Reality::Entity?(Juliana Awada)>
208
- ar.head_of_state.loaded?
209
- # => true
210
- ```
211
-
212
- #### Entity naming
213
-
214
- Currently, reality loads entities just by _Wikipedia page name_ (and
215
- respects redirects the same way Wikipedia does). So, for example:
216
-
217
- ```ruby
218
- # cool:
219
- Reality::Entity('Einstein')
220
- # => #<Reality::Entity(Albert Einstein)>
221
-
222
- # but...
223
- Reality::Entity('Ruby') # => about mineral
224
- Reality::Entity('Ruby (programming language)') # => about programming language
225
- ```
226
-
227
- Further Reality versions would at least work smarter with disambiguation
228
- pages and "other uses" link. But currently, that's just what you have.
105
+ Now, you can use it...
229
106
 
230
- #### Entity additional types
231
-
232
- Let's look at this again:
233
-
234
- ```ruby
235
- ar = Reality::Entity('Argentina')
236
- # => #<Reality::Entity(Argentina):country>
237
- ```
238
-
239
- Final `:country` part means Reality "guessed" desired object type (by
240
- Wikipedia infobox name) and used this to parse additional properties from
241
- Wikipedia, and also add some useful methods. For example (as seen above):
242
-
243
- ```ruby
244
- ar.cities
245
- # => #<Reality::List[Buenos Aires?, "Córdoba, Argentina"?, "Rosario, Santa Fe"?, "Mendoza, Argentina"?, La Plata?, San Miguel de Tucumán?, Mar del Plata?, Salta?, "Santa Fe, Argentina"?, "San Juan, Argentina"?, "Resistencia, Chaco"?, Neuquén?, Santiago del Estero?, Corrientes?, Avellaneda?, Bahía Blanca?, San Salvador de Jujuy?, Quilmes?, Lanús?, Comodoro Rivadavia?, "Concordia, Entre Ríos"?]>
246
- ```
247
-
248
- It is not a property parsed on entry loading (so, it will not be seen
249
- in `#describe`), but helpful method, which fetched additional data from
250
- Wikipedia. (Unfortunately, there are no way to know which "helpful methods"
251
- were added with current entity type, except for scanning `entity.methdods`
252
- by eyes.)
253
-
254
- Also, you should note there are some quirks about this "guess by infobox"
255
- thing. For ex:
107
+ ### ...from your code
256
108
 
257
109
  ```ruby
258
- # ok
259
- Reality::Entity('Buenos Aires')
260
- # => #<Reality::Entity(Buenos Aires):city>
261
-
262
- # not ok: note no "additional type" :city
263
- l = Reality::Entity('Lyon')
264
- # => #<Reality::Entity(Lyon)>
265
- # thats because of:
266
- l.wikipage.infobox.name
267
- # => "Infobox French commune"
268
- ```
269
-
270
- This will become better in future.
271
-
272
- #### Entity internals
273
-
274
- Each entity has `wikipage` and `wikidata` methods, containing data loaded
275
- from Wikipedia and Wikidata respectively. While `wikidata` is pretty ugly
276
- internal object, `wikipage` CAN be useful on its own: it is an instance
277
- of [Infoboxer::MediaWiki::Page](http://www.rubydoc.info/gems/infoboxer/Infoboxer/MediaWiki/Page)
278
- and quite sophisticated and useful object:
279
-
280
- ```ruby
281
- ruby = Reality::Entity('Ruby (programming language)')
282
- puts ruby.wikipage.intro
283
- # Ruby is a dynamic, reflective, object-oriented, general-purpose programming language....
284
- ruby.wikipage.sections
285
- # => [#<Section(level: 2, heading: "History"): ...>, #<Section(level: 2, heading: "Table of versions"): ...>, #<Section(level: 2, heading: "Philosophy"): ...>, ...and so on
286
- ```
287
-
288
- ### Lists
289
-
290
- Let's look closer at this part:
291
-
292
- ```ruby
293
- ar.neighbours
294
- # => #<Reality::List[Uruguay?, Brazil?, Chile?, Paraguay?, Bolivia?]>
295
- ```
296
-
297
- `Reality::List` is just array of entities, with some useful differences.
298
- For example, it provides more concise output (compare with
299
- `ar.neighbours.to_a` on your own). It also provides ability to batch-load
300
- all entities in list:
301
-
302
- ```ruby
303
- # instead of:
304
- # ar.neighbours.each(&:load!)
305
- # ...which will be 5 separate requests to Wikipedia and 5 to Wikidata
306
- # ...you can write:
307
- ar.neighbours.load!
308
- # ...which is 1 request to Wikipedia API and 1 to Wikidata
309
- ```
310
-
311
- And last, for list of loaded entities, it provides pretty `#describe`
312
- method to quickly look inside:
313
-
314
- ```ruby
315
- ar.neighbours.describe
316
- # -------------------------
317
- # #<Reality::List(5 items)>
318
- # -------------------------
319
- # keys: adm_divisions (5), area (5), calling_code (5), capital (5), continent (5), coord (5), country (5), created_at (5), currency (5), follows (1), gdp_nominal (5), gdp_ppp (5), head_of_state (5), highest_point (5), iso2_code (5), iso3_code (5), long_name (5), neighbours (5), organizations (5), part_of (5), population (5), tld (5), tz_offset (5)
320
- # types: country (5)
321
- ```
322
-
323
- (OK, not incredibly useful for now, but provides you with some insights
324
- on "what's inside".)
325
-
326
- Finally, there are some (will be more in future) "default lists" in Reality:
327
-
328
- ```ruby
329
- Reality.countries
330
- # => #<Reality::List[Algeria?, Angola?, Benin?, Botswana?, Burkina Faso?, Burundi?, Cameroon?, Cape Verde?, Central African Republic?, Chad?, Comoros?, Republic of the Congo?, Democratic Republic of the Congo?, Djibouti?, Egypt?, Equatorial Guinea?, Eritrea?, Ethiopia?, Gabon?, Gambia?, Ghana?, Guinea?, Guinea-Bissau?, Ivory Coast?, Kenya?, Lesotho?, Liberia?, Libya?, Madagascar?, Malawi?, Mali?, Mauritania?, Mauritius?, Morocco?, Mozambique?, Namibia?, Niger?, Nigeria?, Rwanda?, São Tomé and Príncipe?, Senegal?, Seychelles?, Sierra Leone?, Somalia?, South Africa?, South Sudan?, Sudan?, Swaziland?, Tanzania?, Togo?, Tunisia?, Uganda?, Zambia?, Zimbabwe?, Afghanistan?, Armenia?, Azerbaijan?, Bahrain?, Bangladesh?, Bhutan?, Brunei?, Cambodia?, China?, Cyprus?, East Timor?, Georgia (country)?, India?, Indonesia?, Iran?, Iraq?, Israel?, Japan?, Jordan?, Kazakhstan?, Kuwait?, Kyrgyzstan?, Laos?, Lebanon?, Malaysia?, Maldives?, Mongolia?, Myanmar?, Nepal?, North Korea?, Oman?, Pakistan?, State of Palestine?, Philippines?, Qatar?, Saudi Arabia?, Singapore?, South Korea?, Sri Lanka?, Syria?, Tajikistan?, Thailand?, Turkey?, Turkmenistan?, United Arab Emirates?, Uzbekistan?, Vietnam?, Yemen?, Albania?, Andorra?, Austria?, Belarus?, Belgium?, Bosnia and Herzegovina?, Bulgaria?, Croatia?, Czech Republic?, Denmark?, Estonia?, Finland?, France?, Germany?, Greece?, Hungary?, Iceland?, Republic of Ireland?, Italy?, Latvia?, Liechtenstein?, Lithuania?, Luxembourg?, Republic of Macedonia?, Malta?, Moldova?, Monaco?, Montenegro?, Kingdom of the Netherlands?, Norway?, Poland?, Portugal?, Romania?, Russia?, San Marino?, Serbia?, Slovakia?, Slovenia?, Spain?, Sweden?, Switzerland?, Ukraine?, United Kingdom?, Vatican City?, Antigua and Barbuda?, Bahamas?, Barbados?, Belize?, Canada?, Costa Rica?, Cuba?, Dominica?, Dominican Republic?, El Salvador?, Grenada?, Guatemala?, Haiti?, Honduras?, Jamaica?, Mexico?, Nicaragua?, Panama?, Saint Kitts and Nevis?, Saint Lucia?, Saint Vincent and the Grenadines?, Trinidad and Tobago?, United States?, Argentina?, Bolivia?, Brazil?, Chile?, Colombia?, Ecuador?, Guyana?, Paraguay?, Peru?, Suriname?, Uruguay?, Venezuela?, Australia?, Fiji?, Kiribati?, Marshall Islands?, Federated States of Micronesia?, Nauru?, New Zealand?, Palau?, Papua New Guinea?, Samoa?, Solomon Islands?, Tonga?, Tuvalu?, Vanuatu?]>
331
- Reality.continents
332
- # => #<Reality::List[Asia?, Africa?, North America?, South America?, Antarctica?, Europe?, Australia (continent)?]>
333
- ```
334
-
335
- Though, there is one funny quirk with latter (still thinking of it):
336
-
337
- ```ruby
338
- Reality.continents.last
339
- # => #<Reality::Entity(Australia (continent)):continent>
340
- Reality.continents.last.countries
341
- # => #<Reality::List[]>
342
- # ????
343
- # Let's see...
344
- a = Reality::Entity('Australia')
345
- # => #<Reality::Entity(Australia):country>
346
- a.continent
347
- # => #<Reality::Entity?(Oceania)>
348
- # Hmmmm....
349
- a.continent.countries
350
- # => #<Reality::List[Australia?, Fiji?, Kiribati?, Marshall Islands?, Federated States of Micronesia?, Nauru?, New Zealand?, Palau?, Papua New Guinea?, Samoa?, Solomon Islands?, Tonga?, Tuvalu?, Vanuatu?]>
351
- ```
352
-
353
- That's kinda weird thing of Wikipedia data ("Countries by continents" and
354
- "List of continents" pages seems to be vague of "continent" and "part of
355
- world" concepts).
356
-
357
- ### Helper classes
358
-
359
- Currently, there are several of them. All are just "handy wrappers"
360
- around some values, that may be (or may be not) replaced with additional
361
- gems in future versions.
362
-
363
- #### Reality::Measure
364
-
365
- ```ruby
366
- ar.population
367
- # => #<Reality::Measure(43,417,000 person)>
368
- ar.population.amount
369
- # => 43,417,000
370
- ar.population.unit
371
- # => #<Reality::Measure::Unit(person)>
372
- ar.population ** 2
373
- # => #<Reality::Measure(1,885,035,889,000,000 person²)>
374
- ar.population / ar.area
375
- # => #<Reality::Measure(15 person/km²)>
376
-
377
- # using on its own:
378
- m = Reality::Measure.new(10, 'm')
379
- # => #<Reality::Measure(10 m)>
380
- m ** 2
381
- # => #<Reality::Measure(100 m²)>
382
- ```
383
-
384
- **NB**: No measure conversion provided for now. Attempt to sum metres with
385
- kilometres will fail miserably. [unitwise](https://github.com/joshwlewis/unitwise)
386
- may be utilised instead or inside `Measure` in future.
387
-
388
- #### Reality::Geo::Coord
110
+ require 'reality'
389
111
 
390
- ```ruby
391
- ar.capital.coord
392
- # => #<Reality::Geo::Coord(34°35′58″S,58°22′54″W)>
393
- ar.capital.coord.to_s
394
- # => "-34.599722222222,-58.381944444444"
395
- ar.capital.coord.distance_to(ar.highest_point.coord)
396
- # => #<Reality::Measure(1,097 km)>
397
- # ar.capital.coord.distance_to(ar.highest_point) also can be used, if highest_point has coord method
398
- ar.capital.coord.direction_to(ar.highest_point.coord)
399
- # => #<Reality::Measure(278 °)>
400
- ```
112
+ th = Reality::Entity('Thailand')
113
+ p th.area / th.population
114
+ # => #<Reality::Measure(0.007 km²/person)>
401
115
 
402
- **NB**: [geokit](https://github.com/geokit/geokit) already somehow
403
- utilized inside.
404
116
 
405
- #### Reality::TZOffset
117
+ list = Reality::List('Terminator', 'Terminator 2', 'Terminator 3', 'Terminator 4', 'Terminator 5')
118
+ # => #<Reality::List[Terminator?, Terminator 2?, Terminator 3?, Terminator 4?, Terminator 5?]>
119
+ list.load!
120
+ # => #<Reality::List[Terminator, Terminator 2: Judgment Day, Terminator 3: Rise of the Machines, Terminator Salvation, Terminator Genisys]>
406
121
 
407
- ```ruby
408
- ar.tz_offset
409
- # => #<Reality::TZOffset(UTC-03:00)>
410
- ar.tz_offset.now
411
- # => 2016-03-01 16:03:52 -0300
412
- ar.tz_offset.local(2016, 3, 2, 14, 30)
413
- # => 2016-03-02 14:30:00 -0300
414
- ar.tz_offset.convert(Time.now)
415
- # => 2016-03-01 16:04:36 -0300
416
-
417
- # using on its own:
418
- Reality::TZOffset.parse('GMT+1').now
419
- # => 2016-03-01 20:05:10 +0100
122
+ p list.map(&:published_at)
123
+ # => [nil, #<Date: 1991-01-01>, #<Date: 2003-01-01>, #<Date: 2009-01-01>, #<Date: 2015-01-01>]
420
124
  ```
421
125
 
422
- ### Using external services
126
+ Start from [Getting started](https://github.com/molybdenum-99/reality/wiki/Getting-started)
127
+ in our wiki and move along the pointers!
423
128
 
424
- Currently, there are two external services (except of Wikipedia and
425
- Wikidata) mashed into Reality:
426
- * [OpenWeatherMap](http://openweathermap.org/) for "current weather"
427
- feature;
428
- * [GeoNames](http://www.geonames.org/) for "timezone at this coordinates"
429
- feature.
129
+ ### ...from command-line
430
130
 
431
- Both of them, unlike Wikipedia/Wikidata API, require free access key
432
- for usage. So, in your own code, you'll see something like this:
131
+ The `reality` command allows you to investigate various
132
+ concepts in your terminal:
433
133
 
434
- ```ruby
435
- ar.capital.coord.weather
436
- # KeyError: Expected keys.open_weather_map to exist in config. It is OpenWeatherMap APPID. Can be obtained here: http://openweathermap.org/appid
437
- ar.capital.coord.timezone
438
- # KeyError: Expected keys.geonames to exist in config. It is GeoNames username. Can be received from http://www.geonames.org/login
439
134
  ```
135
+ $ reality Katmandu
136
+ ----------------------------------
137
+ #<Reality::Entity(Kathmandu):city>
138
+ ----------------------------------
139
+ area: #<Reality::Measure(49 km²)>
140
+ coord: #<Reality::Geo::Coord(27°43′0″N,85°22′0″E)>
141
+ country: #<Reality::Entity?(Nepal)>
142
+ elevation: #<Reality::Measure(1,400 m)>
143
+ located_in: #<Reality::Entity?(Nepal)>
144
+ long_name: "Kathmandu Metropolitan City\nKTM"
145
+ official_website: "http://www.kathmandu.gov.np"
146
+ population: #<Reality::Measure(975,453 person)>
147
+ tz_offset: #<Reality::TZOffset(UTC+05:45)>
440
148
 
441
- For experiments you can use (but not abuse) Reality demo config, like this:
442
149
 
443
- ```ruby
444
- Reality.configure(:demo)
445
- ar.capital.coord.weather
446
- # => #<Reality::Weather(21°C, Clear)>
447
- ar.capital.coord.timezone
448
- # => #<TZInfo::DataTimezone: America/Argentina/Buenos_Aires>
150
+ $ reality Beatles albums first
151
+ Please Please Me
449
152
  ```
450
153
 
451
- For more extensive data usage, you should use `Reality#configure` with
452
- your own config (see `config/demo.yml` for sample of this).
453
-
454
- Note, that reality binary is configured with `:demo` by default.
154
+ See [wikipage](https://github.com/molybdenum-99/reality/wiki/Command-line-usage)
155
+ for details.
455
156
 
456
- ### More
157
+ ### ...from interactive console
457
158
 
458
- There are several things that are not required by `require "reality"` (but
459
- are included in interactive console).
159
+ The `reality -i` command opens interactive console, allowing you to
160
+ investigate Reality's features immediately. It also provides many useful
161
+ shortcuts for less typing:
460
162
 
461
- **Pretty inspect**: `require "reality/pretty_inspect"` redefines `#inspect`
462
- method for some core classes, which are heavily utilized by reality, and
463
- their default `#inspect` is not that pretty. For example:
464
-
465
- ```ruby
466
- # without pretty_inspect
467
- Reality::Entity('Yukihiro Matsumoto').birthday
468
- # => #<Date: 1965-04-14 ((2438865j,0s,0n),+0s,2299161j)>
469
-
470
- # with pretty_inspect
471
- Reality::Entity('Yukihiro Matsumoto').birthday
472
- # => #<Date: 1965-04-14>
473
-
474
- # without pretty_inspect
475
- Reality::Entity('Buenos Aires').population / Reality::Entity('London').population
476
- # => (2890151/8416535)
477
- # ↑ it's Rational, pretty precise, but hard to read
478
-
479
- # with pretty_inspect
480
- Reality::Entity('Buenos Aires').population / Reality::Entity('London').population
481
- # => 0.3
482
- # ↑ it's still the same Rational, but with less precise/more readable output
483
163
  ```
164
+ $ reality -i
484
165
 
485
- **Shortcuts**: `require "reality/shortcuts"` provides you with pretty
486
- concise syntax:
487
-
488
- ```ruby
489
- include Reality
490
-
491
- E('Yukihiro Matsumoto')
492
-
493
- L('Argentine', 'Bolivia', 'Chile')
166
+ reality#1:001:0> b = E('Brno')
167
+ # => #<Reality::Entity(Brno):city>
168
+ reality#1:002:0> b.area
169
+ # => #<Reality::Measure(230 km²)>
170
+ reality#1:003:0> b.coord.weather
171
+ # => #<Reality::Weather(10°C, Rain)>
494
172
  ```
495
173
 
496
- Also, you could do `include Reality::Methods` (instead of `include Reality`)
497
- in your code to not pollute your namespace with anything except `Entity`
498
- and `List` methods (`E` and `L` is also in this namespace after you
499
- have required "reality/shortcuts").
174
+ ...and so on. Read more at [Interactive console](https://github.com/molybdenum-99/reality/wiki/Interactive-console)
175
+ and feel free to experiment!
500
176
 
501
177
  ## Good. What next?..
502
178
 
@@ -515,6 +191,13 @@ not-so-near plans looks like this (order is vague):
515
191
  * large demo-scripts set, maybe in independent repository;
516
192
  * separation of largely independent parts to another gems and libraries.
517
193
 
194
+ ## Docs
195
+
196
+ * [Our wiki](https://github.com/molybdenum-99/reality/wiki) have pretty
197
+ comprehensive docs now, from Tutorial to some advanced topics;
198
+ * [YARD docs](http://www.rubydoc.info/gems/reality) are mostly written
199
+ and contain explanations, examples and definitions.
200
+
518
201
  ## Want to help?
519
202
 
520
203
  Great!
@@ -532,14 +215,28 @@ Currently, it would be great if somebody lay their hands on:
532
215
  **and** make this city a `Reality::Entity`);
533
216
  * play with Reality and share your experiences and examples and problems
534
217
  and cool demos!
218
+
219
+ [Contributing](https://github.com/molybdenum-99/reality/wiki/Contributing)
220
+ page in wiki explains some things a bit deeper.
221
+
222
+ ## Compatibility
223
+
224
+ Ruby 2+ is a must (we love refinements, keywords arguments and other
225
+ cool stuff). JRuby & Rubinius compatibility was not checked still, help
226
+ would be appreciated here!
227
+
228
+ Note that there could be a problem with SSL sertificates while connecting
229
+ to Wikipedia API. _TODO: explain the problem and point to recipes._
535
230
 
536
231
  ## Credits
537
232
 
538
233
  * [Victor Shepelev](https://zverok.github.io) [@zverok](https://github.com/zverok);
539
- * Sergey Mostovoy [@smostovoy](https://github.com/smostovoy).
234
+ * Sergey Mostovoy [@smostovoy](https://github.com/smostovoy);
235
+ * [Valentino Stoll](http://www.awesomevibe.com/) [@codenamev](https://github.com/codenamev);
236
+ * [Several great contributors](https://github.com/molybdenum-99/reality/graphs/contributors).
540
237
 
541
- Development sponsored by
542
- [2015 Ruby Association Grant](http://www.ruby.or.jp/en/news/20151116.html).
238
+ Development of first version was sponsored by
239
+ [2015 Ruby Association Grant](http://www.ruby.or.jp/en/news/20160406.html).
543
240
 
544
241
  Initial idea is inspired by "integrated data" of
545
242
  [Wolfram Language](http://reference.wolfram.com/language/).