infoboxer 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +1 -0
  3. data/CHANGELOG.md +6 -0
  4. data/bin/infoboxer +11 -12
  5. data/infoboxer.gemspec +3 -2
  6. data/lib/infoboxer/core_ext.rb +1 -0
  7. data/lib/infoboxer/definitions/en.wikipedia.org.rb +13 -13
  8. data/lib/infoboxer/media_wiki/page.rb +4 -3
  9. data/lib/infoboxer/media_wiki/traits.rb +12 -10
  10. data/lib/infoboxer/media_wiki.rb +97 -68
  11. data/lib/infoboxer/navigation/lookup.rb +30 -26
  12. data/lib/infoboxer/navigation/sections.rb +33 -37
  13. data/lib/infoboxer/navigation/selector.rb +5 -6
  14. data/lib/infoboxer/navigation/shortcuts.rb +12 -11
  15. data/lib/infoboxer/navigation.rb +2 -1
  16. data/lib/infoboxer/parser/context.rb +12 -13
  17. data/lib/infoboxer/parser/html.rb +7 -6
  18. data/lib/infoboxer/parser/image.rb +25 -29
  19. data/lib/infoboxer/parser/inline.rb +82 -79
  20. data/lib/infoboxer/parser/paragraphs.rb +34 -37
  21. data/lib/infoboxer/parser/table.rb +26 -27
  22. data/lib/infoboxer/parser/template.rb +12 -4
  23. data/lib/infoboxer/parser/util.rb +11 -16
  24. data/lib/infoboxer/parser.rb +8 -1
  25. data/lib/infoboxer/templates/base.rb +3 -3
  26. data/lib/infoboxer/templates/set.rb +11 -10
  27. data/lib/infoboxer/tree/compound.rb +7 -6
  28. data/lib/infoboxer/tree/document.rb +1 -0
  29. data/lib/infoboxer/tree/html.rb +5 -4
  30. data/lib/infoboxer/tree/image.rb +8 -7
  31. data/lib/infoboxer/tree/inline.rb +4 -5
  32. data/lib/infoboxer/tree/linkable.rb +3 -5
  33. data/lib/infoboxer/tree/list.rb +15 -16
  34. data/lib/infoboxer/tree/node.rb +11 -10
  35. data/lib/infoboxer/tree/nodes.rb +24 -23
  36. data/lib/infoboxer/tree/paragraphs.rb +3 -2
  37. data/lib/infoboxer/tree/ref.rb +6 -3
  38. data/lib/infoboxer/tree/table.rb +13 -13
  39. data/lib/infoboxer/tree/template.rb +15 -15
  40. data/lib/infoboxer/tree/text.rb +2 -1
  41. data/lib/infoboxer/tree/wikilink.rb +9 -8
  42. data/lib/infoboxer/tree.rb +3 -2
  43. data/lib/infoboxer/version.rb +2 -1
  44. data/lib/infoboxer.rb +24 -26
  45. data/regression/pages/wyoming.wiki +1085 -0
  46. metadata +8 -21
  47. data/lib/infoboxer/media_wiki/mediawiktory_patch.rb +0 -23
data/lib/infoboxer.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'procme'
3
- require 'backports/2.1.0/array/to_h'
4
- #require 'backports/2.2.0/object/itself' Y U NO???
5
4
 
6
5
  # Main client module for entire infoboxer functionality. If you're lucky,
7
6
  # there's no other classes/modules you need to instantiate or call
@@ -9,7 +8,7 @@ require 'backports/2.1.0/array/to_h'
9
8
  #
10
9
  # ```ruby
11
10
  # Infoboxer.wp.get('List of radio telescopes')
12
- # # or
11
+ # # or
13
12
  # Infoboxer.wikiquote.get('Vonnegut')
14
13
  # ```
15
14
  # ...and have fully navigable Wiki information.
@@ -49,10 +48,10 @@ require 'backports/2.1.0/array/to_h'
49
48
  # ```
50
49
  #
51
50
  module Infoboxer
52
- private # hiding constants from YARD
53
-
54
- WIKIA_API_URL = 'http://%s.wikia.com/api.php'
51
+ # @private
52
+ WIKIA_API_URL = 'http://%s.wikia.com/api.php'.freeze
55
53
 
54
+ # @private
56
55
  WIKIMEDIA_PROJECTS = {
57
56
  wikipedia: 'wikipedia.org',
58
57
  wikivoyage: 'wikivoyage.org',
@@ -62,20 +61,21 @@ module Infoboxer
62
61
  wikinews: 'wikinews.org',
63
62
  wikiversity: 'wikiversity.org',
64
63
  wikisource: 'wikisource.org'
65
- }
64
+ }.freeze
66
65
 
66
+ # @private
67
67
  WIKIMEDIA_COMMONS = {
68
68
  commons: 'commons.wikimedia.org',
69
69
  species: 'species.wikimedia.org',
70
- }
70
+ }.freeze
71
71
 
72
- WIKIS = {}
72
+ def wikis
73
+ @wikis ||= {}
74
+ end
73
75
 
74
- public
75
-
76
76
  # Includeable version of {Infoboxer.wiki}
77
77
  def wiki(api_url, options = {})
78
- WIKIS[api_url] ||= MediaWiki.new(api_url, options || {})
78
+ wikis[api_url] ||= MediaWiki.new(api_url, options || {})
79
79
  end
80
80
 
81
81
  class << self
@@ -92,20 +92,20 @@ module Infoboxer
92
92
  # ```ruby
93
93
  # Infoboxer.wiki('some_url').get('Some page title')
94
94
  # ```
95
-
95
+
96
96
  # @!method wikipedia(lang = 'en', options = {})
97
97
  # Shortcut for creating Wikipedia client.
98
98
  #
99
99
  # @param lang two-character code for language version
100
100
  # @param options (see #wiki for list of options)
101
101
  # @return [MediaWiki]
102
-
102
+
103
103
  # @!method commons(options = {})
104
104
  # Shortcut for creating [WikiMedia Commons](https://commons.wikimedia.org/) client.
105
105
  #
106
106
  # @param options (see #wiki for list of options)
107
107
  # @return [MediaWiki]
108
-
108
+
109
109
  # @!method wikibooks(lang = 'en', options = {})
110
110
  # Shortcut for creating [Wikibooks](https://en.wikibooks.org/) client.
111
111
  # See {wikipedia} for params explanation.
@@ -141,7 +141,7 @@ module Infoboxer
141
141
  #
142
142
  # @param options (see #wiki for list of options)
143
143
  # @return [MediaWiki]
144
-
144
+
145
145
  # @!method wiktionary(lang = 'en', options = {})
146
146
  # Shortcut for creating [Wiktionary](https://en.wiktionary.org/) client.
147
147
  # See {wikipedia} for params explanation.
@@ -152,13 +152,13 @@ module Infoboxer
152
152
  #
153
153
  # @overload wikia(*domains)
154
154
  # @param *domains list of domains to merge, like this:
155
- #
155
+ #
156
156
  # ```ruby
157
157
  # Infoboxer.wikia('tardis') # looks at tardis.wikia.com
158
158
  # Infoboxer.wikia('tardis', 'ru') # looks in Russian version, ru.tardis.wikia.com
159
159
  # ```
160
160
  # If you are surprised by "reversing" list of subdomains, think of
161
- # it as of chain of refinements (looking in "tardis" wiki, its "ru"
161
+ # it as of chain of refinements (looking in "tardis" wiki, its "ru"
162
162
  # version, specifically).
163
163
  #
164
164
  # @overload wikia(*domains, options)
@@ -171,9 +171,7 @@ module Infoboxer
171
171
 
172
172
  WIKIMEDIA_PROJECTS.each do |name, domain|
173
173
  define_method name do |lang = 'en', options = {}|
174
- if lang.is_a?(Hash)
175
- lang, options = 'en', lang
176
- end
174
+ lang, options = 'en', lang if lang.is_a?(Hash)
177
175
 
178
176
  wiki("https://#{lang}.#{domain}/w/api.php", options)
179
177
  end
@@ -189,10 +187,10 @@ module Infoboxer
189
187
 
190
188
  # @!method wikipedia(lang = 'en', options = {})
191
189
  # Includeable version of {Infoboxer.wikipedia}
192
-
190
+
193
191
  # @!method commons(options = {})
194
192
  # Includeable version of {Infoboxer.commons}
195
-
193
+
196
194
  # @!method wikibooks(lang = 'en', options = {})
197
195
  # Includeable version of {Infoboxer.wikibooks}
198
196
 
@@ -213,7 +211,7 @@ module Infoboxer
213
211
 
214
212
  # @!method species(options = {})
215
213
  # Includeable version of {Infoboxer.species}
216
-
214
+
217
215
  # @!method wiktionary(lang = 'en', options = {})
218
216
  # Includeable version of {Infoboxer.wiktionary}
219
217
 
@@ -223,14 +221,14 @@ module Infoboxer
223
221
  wiki(WIKIA_API_URL % domains.reverse.join('.'), options)
224
222
  end
225
223
 
226
- # Sets user agent string globally. Default user agent is
224
+ # Sets user agent string globally. Default user agent is
227
225
  # {MediaWiki::UA}.
228
226
  #
229
227
  # User agent can also be rewriten as an option to {wiki} method (and
230
228
  # its shortcuts like {wikipedia}), or by using {MediaWiki#initialize}
231
229
  # explicitly.
232
230
  #
233
- def Infoboxer.user_agent=(ua)
231
+ def self.user_agent=(ua)
234
232
  MediaWiki.user_agent = ua
235
233
  end
236
234