wikidata-client 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: 3a47b99cc065919cae23f6814ef438317834ef88
4
- data.tar.gz: 15c43966bb2829da222915cf79b62ec2f6b8aa92
3
+ metadata.gz: 660f225f214426620269fe2e615054f60b102bb2
4
+ data.tar.gz: ae8d04c5541614688a17e5892841f6ca3c99b216
5
5
  SHA512:
6
- metadata.gz: 850765921f85b991bd8c55eeef67c456ee0b95b4a547c1e77f6f419ce8c4be1dd7e63fb83252ff2bb5ee82010ecaad4a22271cac2283ddc9c7b3f3ca5bebdb43
7
- data.tar.gz: 0acedc3ef7a2c35f9191a2721c3e19e12459838f9eaadb9a46b3e85f40d54f0c0cebd6c10c4d0b1149be5fb982ca4e2c870946898488c5b51a157e0671e84c2c
6
+ metadata.gz: f52b79de4b18cb152dde5ea06f55192912435ea3476e516c95aa1eb930e07419c67bcfc792b49bc66da645db0ef23f8b60a5517c31d779bfd2024f6cea97fce8
7
+ data.tar.gz: bf5c352664f7290b14683cfd1e45448580dca4cb158708c08beebc99befb57553b9b199dab4ce675af95f5a5fb482d7294adfc5ffdabb292b9ee29fc21e875b0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.4
4
+
5
+ - HTTP client options more easily configurable
6
+ - Improve date range parser
7
+
3
8
  ## 0.0.3
4
9
 
5
10
  - Jruby support
data/Gemfile.lock CHANGED
@@ -2,7 +2,6 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  wikidata-client (0.0.3)
5
- excon (~> 0.40)
6
5
  faraday (~> 0.9)
7
6
  faraday_middleware (~> 0.9)
8
7
  hashie (~> 3.3)
@@ -70,6 +69,7 @@ PLATFORMS
70
69
 
71
70
  DEPENDENCIES
72
71
  codeclimate-test-reporter
72
+ excon (~> 0.40)
73
73
  pry (~> 0.10)
74
74
  rake (~> 10.3)
75
75
  rspec (~> 3.1)
data/README.md CHANGED
@@ -14,7 +14,7 @@ It provide an easy way to search for wikidata pages and read their contents.
14
14
 
15
15
  ## Installation
16
16
 
17
- In bunler: `gem 'wikidata-client', '~> 0.0.3', require: 'wikidata'`
17
+ In bunler: `gem 'wikidata-client', '~> 0.0.4', require: 'wikidata'`
18
18
 
19
19
  Otherwise: `gem install wikidata-client`
20
20
 
@@ -26,13 +26,13 @@ Only one thing is configurable for now, the HTTP client and its options, via
26
26
 
27
27
  ```ruby
28
28
  Wikidata.configure do |config|
29
- config.faraday = -> (builder) {
30
- builder.options[:request] = {
29
+ config.options = {
30
+ request: {
31
31
  timeout: 10,
32
32
  open_timeout: 2
33
33
  }
34
- builder.adapter :patron
35
34
  }
35
+ config.faraday = -> (builder) { builder.adapter :patron }
36
36
  end
37
37
  ```
38
38
 
data/config/mapping.yml CHANGED
@@ -12,6 +12,9 @@ resources:
12
12
  coordinate_location: P625
13
13
  freebase_identifier: P646
14
14
  father: P22
15
+ start_date: P580
16
+ end_date: P582
17
+ point_in_time: P585
15
18
  collections:
16
19
  official_websites: P856
17
20
  instance_of: P31
@@ -26,7 +26,8 @@ module Wikidata
26
26
  end
27
27
 
28
28
  def api
29
- Faraday.new(url: Wikidata.settings.api.url) do |faraday|
29
+ opts = Wikidata.options.merge url: Wikidata.settings.api.url
30
+ Faraday.new(opts) do |faraday|
30
31
  faraday.request :url_encoded
31
32
  faraday.response :json, content_type: /\bjson$/
32
33
  Wikidata.faraday.call faraday
@@ -1,13 +1,14 @@
1
1
  module Wikidata
2
2
  class Config
3
3
  class << self
4
- attr_accessor :faraday, :settings, :mapping
4
+ attr_accessor :options, :faraday, :settings, :mapping
5
5
 
6
6
  def configure &block
7
7
  yield self
8
8
  end
9
9
  end
10
10
 
11
+ @options = {}
11
12
  @faraday = -> (builder) { builder.adapter :excon }
12
13
  @settings = Hashie::Mash.new(
13
14
  YAML.load_file(
@@ -64,6 +64,7 @@ module Wikidata
64
64
  # TODO Handle other types
65
65
  # http://www.wikidata.org/wiki/Wikidata:Glossary#Entities.2C_items.2C_properties_and_queries
66
66
  def entity_id attribute
67
+ return unless attribute.mainsnak.datavalue
67
68
  attribute.mainsnak.datavalue.value.tap do |h|
68
69
  case h['entity-type']
69
70
  when 'item'
@@ -2,27 +2,42 @@ module Wikidata
2
2
  module Property
3
3
  class Time < Wikidata::Property::Base
4
4
  DATE_PRECISION = {
5
- 0 => 1_000_000_000 * 365 * 24 * 3600,
6
- 1 => 100_000_000 * 365 * 24 * 3600,
7
- 2 => 10_000_000 * 365 * 24 * 3600,
8
- 3 => 1_000_000 * 365 * 24 * 3600,
9
- 4 => 100_000 * 365 * 24 * 3600,
10
- 5 => 10_000 * 365 * 24 * 3600,
11
- 6 => 1000 * 365 * 24 * 3600,
12
- 7 => 100 * 365 * 24 * 3600,
13
- 8 => 10 * 365 * 24 * 3600,
14
- 9 => 365 * 24 * 3600,
15
- 10 => 30 * 24 * 3600,
16
- 11 => 24 * 3600,
17
- 12 => 3600,
18
- 13 => 60,
19
- 14 => 1
5
+ 0 => { key: nil, value: 1_000_000_000 * 365 * 24 * 3600 },
6
+ 1 => { key: nil, value: 100_000_000 * 365 * 24 * 3600 },
7
+ 2 => { key: nil, value: 10_000_000 * 365 * 24 * 3600 },
8
+ 3 => { key: nil, value: 1_000_000 * 365 * 24 * 3600 },
9
+ 4 => { key: nil, value: 100_000 * 365 * 24 * 3600 },
10
+ 5 => { key: nil, value: 10_000 * 365 * 24 * 3600 },
11
+ 6 => { key: nil, value: 1000 * 365 * 24 * 3600 },
12
+ 7 => { key: :century, value: 100 * 365 * 24 * 3600 },
13
+ 8 => { key: :decade, value: 10 * 365 * 24 * 3600 },
14
+ 9 => { key: :year, value: 365 * 24 * 3600 },
15
+ 10 => { key: :month, value: 30 * 24 * 3600 },
16
+ 11 => { key: :day, value: 24 * 3600 },
17
+ 12 => { key: nil, value: 3600 },
18
+ 13 => { key: nil, value: 60 },
19
+ 14 => { key: nil, value: 1 }
20
20
  }.freeze
21
21
 
22
+ DAYS_IN_MONTH = {
23
+ 1 => 31,
24
+ 2 => 28,
25
+ 3 => 31,
26
+ 4 => 30,
27
+ 5 => 31,
28
+ 6 => 30,
29
+ 7 => 31,
30
+ 8 => 31,
31
+ 9 => 30,
32
+ 10 => 31,
33
+ 11 => 30,
34
+ 12 => 31
35
+ }
36
+
22
37
  def date
23
38
  return @_date if @_date
24
39
  d = Hash[[:year, :month, :day, :hour, :min, :sec].zip(
25
- value.time.scan(/\d*/).reject!{|e| e == ""}.map(&:to_i)
40
+ value.time.scan(/(-?\d+)-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/).first.map(&:to_i)
26
41
  )]
27
42
  [:month, :day].each do |k|
28
43
  d[k] = (d[k] == 0 ? 1 : d[k])
@@ -35,7 +50,11 @@ module Wikidata
35
50
  end
36
51
 
37
52
  def precision
38
- DATE_PRECISION[value.precision.to_i]
53
+ DATE_PRECISION[value.precision.to_i][:value]
54
+ end
55
+
56
+ def precision_key
57
+ DATE_PRECISION[value.precision.to_i][:key]
39
58
  end
40
59
 
41
60
  def after
@@ -48,25 +67,79 @@ module Wikidata
48
67
 
49
68
  def range
50
69
  return @_range if @_range
70
+
71
+ if before.to_i == 0 && after.to_i == 0 && precision_key
72
+ send(:"#{precision_key}_range")
73
+ else
74
+ generic_range
75
+ end
76
+ end
77
+
78
+ protected
79
+
80
+ def generic_range
51
81
  from = before > 0 ?
52
82
  timestamp - (before.to_i * precision) : timestamp
53
83
  to = after > 0 ?
54
84
  timestamp + (after.to_i * precision) : timestamp
55
85
 
56
- # Make sure we respect wikidata precision in case we have after/before to 0
57
- if (min_to = timestamp + precision) > to
58
- min_to_date = ::Time.at(min_to)
59
- to = DateTime.new(min_to_date.year, min_to_date.month, min_to_date.day, 23, 59, 59).to_time.utc.to_i
86
+ @_range ||= (to_datetime ::Time.at(from).utc)..(to_datetime ::Time::at(to).utc)
87
+ end
88
+
89
+ def century_range
90
+ century = date.year / 100
91
+ if date.year > 0
92
+ from = DateTime.new((century - 1) * 100 + 1, 1, 1, 0, 0, 0)
93
+ to = DateTime.new(century * 100, 12, 31, 23, 59, 59)
94
+ else
95
+ from = DateTime.new(century * 100, 1, 1, 0, 0, 0)
96
+ to = DateTime.new((century + 1) * 100 - 1, 12, 31, 23, 59, 59)
60
97
  end
98
+ @_range ||= (from..to)
99
+ end
61
100
 
62
- @_range ||= (to_datetime ::Time.at(from).utc)..(to_datetime ::Time::at(to).utc)
101
+ def year_range
102
+ from = DateTime.new(date.year, 1, 1, 0, 0, 0)
103
+ to = DateTime.new(date.year, 12, 31, 23, 59, 59)
104
+ @_range ||= (from..to)
63
105
  end
64
106
 
65
- protected
107
+ def decade_range
108
+ decade = date.year.round(-1)
109
+ if decade > 0
110
+ from = DateTime.new(decade, 1, 1, 0, 0, 0)
111
+ to = DateTime.new(decade + 9, 12, 31, 23, 59, 59)
112
+ else
113
+ from = DateTime.new(decade - 9, 1, 1, 0, 0, 0)
114
+ to = DateTime.new(decade, 12, 31, 23, 59, 59)
115
+ end
116
+ @_range ||= (from..to)
117
+ end
118
+
119
+ def month_range
120
+ if date.month == 2 && self.class.leap_year?(date.year)
121
+ last_day = 29
122
+ else
123
+ last_day = DAYS_IN_MONTH[date.month]
124
+ end
125
+ from = DateTime.new(date.year, date.month, 1, 0, 0, 0)
126
+ to = DateTime.new(date.year, date.month, last_day, 23, 59, 59)
127
+ @_range ||= (from..to)
128
+ end
129
+
130
+ def day_range
131
+ from = DateTime.new(date.year, date.month, date.day, 0, 0, 0)
132
+ to = DateTime.new(date.year, date.month, date.day, 23, 59, 59)
133
+ @_range ||= (from..to)
134
+ end
66
135
 
67
136
  def to_datetime(t)
68
137
  DateTime.new t.year, t.month, t.day, t.hour, t.min, t.sec
69
138
  end
139
+
140
+ def self.leap_year? year
141
+ (year % 4 == 0) && !(year % 100 == 0) || (year % 400 == 0)
142
+ end
70
143
  end
71
144
  end
72
145
  end
@@ -1,7 +1,7 @@
1
1
  module Wikidata
2
2
  module Property
3
3
  def self.build attribute
4
- return if attribute.mainsnak.snaktype == "somevalue"
4
+ return if %w{somevalue novalue}.include? attribute.mainsnak.snaktype
5
5
  case attribute.mainsnak.datatype
6
6
  when 'string'
7
7
  Wikidata::Property::String.new attribute
@@ -14,7 +14,7 @@ module Wikidata
14
14
  when 'wikibase-item'
15
15
  Wikidata::Item.find Wikidata::Entity.entity_id(attribute)
16
16
  else
17
- raise "Unkown property type #{attribute.mainsnak.datatype}"
17
+ puts "Unkown property type #{attribute.mainsnak.datatype}"
18
18
  end
19
19
  end
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module Wikidata
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
data/lib/wikidata.rb CHANGED
@@ -2,7 +2,6 @@ require 'faraday'
2
2
  require 'faraday_middleware'
3
3
  require 'hashie'
4
4
  require 'yaml'
5
- require 'excon'
6
5
 
7
6
  require 'wikidata/config'
8
7
 
@@ -16,6 +15,10 @@ module Wikidata
16
15
  Config.faraday
17
16
  end
18
17
 
18
+ def options
19
+ Config.options
20
+ end
21
+
19
22
  def settings
20
23
  Config.settings
21
24
  end
@@ -68,9 +68,6 @@ describe Wikidata::Entity, :vcr do
68
68
  homer.property('P569').tap do |date|
69
69
  date.should be_kind_of Wikidata::Property::Time
70
70
  date.date.should eq DateTime.new(1956, 6, 18)
71
- date.range.should eq(
72
- (DateTime.new(1956, 6, 18, 0, 0, 0)..DateTime.new(1956, 6, 19, 23, 59, 59))
73
- )
74
71
  end
75
72
  end
76
73
 
@@ -78,9 +75,6 @@ describe Wikidata::Entity, :vcr do
78
75
  homer.date_of_birth.tap do |date|
79
76
  date.should be_kind_of Wikidata::Property::Time
80
77
  date.date.should eq DateTime.new(1956, 6, 18)
81
- date.range.should eq(
82
- (DateTime.new(1956, 6, 18, 0, 0, 0)..DateTime.new(1956, 6, 19, 23, 59, 59))
83
- )
84
78
  end
85
79
  end
86
80
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Wikidata::Property::Time do
4
- let(:joconde) { Wikidata::Item.find_by_title 'Mona Lisa' }
5
4
  let(:range_of_year) {
6
5
  described_class.new(
7
6
  {
@@ -50,7 +49,301 @@ describe Wikidata::Property::Time do
50
49
  )
51
50
  }
52
51
 
53
- it 'should return Time from a a key (date_of_foundation_or_creation here)' do
52
+ let(:bc_date) {
53
+ described_class.new(
54
+ {
55
+ "id" => "Q7463501$d6247f70-4dcf-afcd-81af-6e20f0d85c3a",
56
+ "mainsnak" => {
57
+ "snaktype" => "value",
58
+ "property" => "P580",
59
+ "datatype" => "time",
60
+ "datavalue" => {
61
+ "value" => {
62
+ "time" => "-00002500000-01-01T00:00:00Z",
63
+ "timezone" => 0,
64
+ "before" => 0,
65
+ "after" => 0,
66
+ "precision" => 4,
67
+ "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
68
+ },
69
+ "type" => "time"
70
+ }
71
+ },
72
+ "qualifiers" => {
73
+ "P518" => [
74
+ {
75
+ "hash" => "34768c4845167709a7bcf6a10da46bf1bd0b7232",
76
+ "snaktype" => "value",
77
+ "property" => "P518",
78
+ "datatype" => "wikibase-item",
79
+ "datavalue" => {
80
+ "value" => {
81
+ "entity-type" => "item",
82
+ "numeric-id" => 15
83
+ },
84
+ "type" => "wikibase-entityid"
85
+ }
86
+ }
87
+ ]
88
+ },
89
+ "qualifiers-order" => ["P518"],
90
+ "type" => "statement",
91
+ "rank" => "normal"
92
+ }
93
+ )
94
+ }
95
+
96
+ let(:century) {
97
+ described_class.new(
98
+ {
99
+ "id" => "Q7061$34CD4AAF-6C99-47CF-AE0E-1E0941C90F1E",
100
+ "mainsnak" => {
101
+ "snaktype" => "value",
102
+ "property" => "P585",
103
+ "datatype" => "time",
104
+ "datavalue" => {
105
+ "value" => {
106
+ "time" => "+00000001200-01-01T00:00:00Z",
107
+ "timezone" => 0,
108
+ "before" => 0,
109
+ "after" => 0,
110
+ "precision" => 7,
111
+ "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
112
+ },
113
+ "type" => "time"
114
+ }
115
+ },
116
+ "type"=>"statement",
117
+ "rank"=>"normal"
118
+ }
119
+ )
120
+ }
121
+
122
+ let(:century_bc) {
123
+ described_class.new(
124
+ {
125
+ "id" => "Q171812$DEB83BAE-F6E0-48D4-B45B-7E15B252F726",
126
+ "mainsnak" => {
127
+ "snaktype" => "value",
128
+ "property" => "P585",
129
+ "datatype" => "time",
130
+ "datavalue" => {
131
+ "value" => {
132
+ "time" => "-00000001200-01-01T00:00:00Z",
133
+ "timezone" => 0,
134
+ "before" => 0,
135
+ "after" => 0,
136
+ "precision" => 7,
137
+ "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
138
+ },
139
+ "type" => "time"
140
+ }
141
+ },
142
+ "type" => "statement",
143
+ "rank" => "normal"
144
+ }
145
+ )
146
+ }
147
+
148
+ let(:year) {
149
+ # http://www.wikidata.org/wiki/Q1118295
150
+ described_class.new(
151
+ {
152
+ "id" => "Q1118295$DD125010-18CF-4280-9FB4-74735B5B8050",
153
+ "mainsnak" => {
154
+ "snaktype"=>"value",
155
+ "property"=>"P571",
156
+ "datatype"=>"time",
157
+ "datavalue"=>{
158
+ "value"=>{
159
+ "time"=>"+00000001888-01-01T00:00:00Z",
160
+ "timezone"=>0,
161
+ "before"=>0,
162
+ "after"=>0,
163
+ "precision"=>9,
164
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
165
+ },
166
+ "type"=>"time"
167
+ }
168
+ },
169
+ "type"=>"statement",
170
+ "rank"=>"normal"
171
+ }
172
+ )
173
+ }
174
+
175
+ let(:decade) {
176
+ # http://www.wikidata.org/wiki/Q35014
177
+ described_class.new(
178
+ {
179
+ "id"=>"Q35014$1B2CDE81-418E-4B0A-A775-408523C085B8",
180
+ "mainsnak"=> {
181
+ "snaktype"=>"value",
182
+ "property"=>"P585",
183
+ "datatype"=>"time",
184
+ "datavalue"=> {
185
+ "value"=>{
186
+ "time"=>"+00000001970-01-01T00:00:00Z",
187
+ "timezone"=>0,
188
+ "before"=>0,
189
+ "after"=>0,
190
+ "precision"=>8,
191
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
192
+ },
193
+ "type"=>"time"
194
+ }
195
+ },
196
+ "type"=>"statement",
197
+ "rank"=>"normal"
198
+ }
199
+ )
200
+ }
201
+
202
+ let(:decade_bc) {
203
+ # http://www.wikidata.org/wiki/Q35014
204
+ described_class.new(
205
+ {
206
+ "id"=>"Q35014$1B2CDE81-418E-4B0A-A775-408523C085B8",
207
+ "mainsnak"=> {
208
+ "snaktype"=>"value",
209
+ "property"=>"P585",
210
+ "datatype"=>"time",
211
+ "datavalue"=> {
212
+ "value"=>{
213
+ "time"=>"-00000001970-01-01T00:00:00Z",
214
+ "timezone"=>0,
215
+ "before"=>0,
216
+ "after"=>0,
217
+ "precision"=>8,
218
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
219
+ },
220
+ "type"=>"time"
221
+ }
222
+ },
223
+ "type"=>"statement",
224
+ "rank"=>"normal"
225
+ }
226
+ )
227
+ }
228
+
229
+ let(:month_leap) {
230
+ described_class.new(
231
+ {
232
+ "id"=>"Q35014$1B2CDE81-418E-4B0A-A775-408523C085B8",
233
+ "mainsnak"=> {
234
+ "snaktype"=>"value",
235
+ "property"=>"P585",
236
+ "datatype"=>"time",
237
+ "datavalue"=> {
238
+ "value"=>{
239
+ "time"=>"+00000002000-02-01T00:00:00Z",
240
+ "timezone"=>0,
241
+ "before"=>0,
242
+ "after"=>0,
243
+ "precision"=>10,
244
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
245
+ },
246
+ "type"=>"time"
247
+ }
248
+ },
249
+ "type"=>"statement",
250
+ "rank"=>"normal"
251
+ }
252
+ )
253
+ }
254
+
255
+ let(:month_31) {
256
+ described_class.new(
257
+ {
258
+ "id"=>"Q35014$1B2CDE81-418E-4B0A-A775-408523C085B8",
259
+ "mainsnak"=> {
260
+ "snaktype"=>"value",
261
+ "property"=>"P585",
262
+ "datatype"=>"time",
263
+ "datavalue"=> {
264
+ "value"=>{
265
+ "time"=>"+00000001968-05-15T00:00:00Z",
266
+ "timezone"=>0,
267
+ "before"=>0,
268
+ "after"=>0,
269
+ "precision"=>10,
270
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
271
+ },
272
+ "type"=>"time"
273
+ }
274
+ },
275
+ "type"=>"statement",
276
+ "rank"=>"normal"
277
+ }
278
+ )
279
+ }
280
+
281
+ let(:month_30) {
282
+ described_class.new(
283
+ {
284
+ "id"=>"Q35014$1B2CDE81-418E-4B0A-A775-408523C085B8",
285
+ "mainsnak"=> {
286
+ "snaktype"=>"value",
287
+ "property"=>"P585",
288
+ "datatype"=>"time",
289
+ "datavalue"=> {
290
+ "value"=>{
291
+ "time"=>"+00000001968-06-15T00:00:00Z",
292
+ "timezone"=>0,
293
+ "before"=>0,
294
+ "after"=>0,
295
+ "precision"=>10,
296
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
297
+ },
298
+ "type"=>"time"
299
+ }
300
+ },
301
+ "type"=>"statement",
302
+ "rank"=>"normal"
303
+ }
304
+ )
305
+ }
306
+
307
+ let(:day) {
308
+ described_class.new(
309
+ {
310
+ "mainsnak" => {
311
+ "snaktype" => "value",
312
+ "property" => "P569",
313
+ "datatype" => "time",
314
+ "datavalue" => {
315
+ "value" => {
316
+ "time" => "+00000001956-06-18T00:00:00Z",
317
+ "timezone" => 0,
318
+ "before" => 0,
319
+ "after" => 0,
320
+ "precision" => 11,
321
+ "calendarmodel"=>"http://www.wikidata.org/entity/Q1985727"
322
+ },
323
+ "type" => "time"
324
+ }
325
+ },
326
+ "type" => "statement",
327
+ "rank"=>"normal"
328
+ }
329
+ )
330
+ }
331
+
332
+
333
+ describe 'leap year' do
334
+ [1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016].each do |y|
335
+ it "should be true for #{y}" do
336
+ described_class.leap_year?(y).should eq true
337
+ end
338
+ end
339
+ [1974, 1978, 2014].each do |y|
340
+ it "should be false for #{y}" do
341
+ described_class.leap_year?(y).should eq false
342
+ end
343
+ end
344
+ end
345
+
346
+ it 'should return a range of DateTime' do
54
347
  range_of_year.tap do |date|
55
348
  date.should be_kind_of Wikidata::Property::Time
56
349
  date.date.should eq DateTime.new(1503, 1, 1)
@@ -58,4 +351,55 @@ describe Wikidata::Property::Time do
58
351
  date.range.max.should eq DateTime.new(1505, 12, 31, 00, 00, 00)
59
352
  end
60
353
  end
354
+
355
+ it 'should handle BC dates' do
356
+ bc_date.date.should eq DateTime.new(-2500000, 1, 1, 0, 0, 0)
357
+ bc_date.range.min.should eq DateTime.new(-2500000, 1, 1, 0, 0, 0)
358
+ bc_date.range.max.should eq DateTime.new(-2500000, 1, 1, 0, 0, 0)
359
+ end
360
+
361
+ it 'should handle centuries' do
362
+ century.range.min.should eq DateTime.new(1101, 1, 1, 0, 0, 0)
363
+ century.range.max.should eq DateTime.new(1200, 12, 31, 23, 59, 59)
364
+ end
365
+
366
+ it 'should handle centuries BC' do
367
+ century_bc.range.min.should eq DateTime.new(-1200, 1, 1, 0, 0, 0)
368
+ century_bc.range.max.should eq DateTime.new(-1101, 12, 31, 23, 59, 59)
369
+ end
370
+
371
+ it 'should handle year' do
372
+ year.range.min.should eq DateTime.new(1888, 1, 1, 0, 0, 0)
373
+ year.range.max.should eq DateTime.new(1888, 12, 31, 23, 59, 59)
374
+ end
375
+
376
+ it 'should handle decade' do
377
+ decade.range.min.should eq DateTime.new(1970, 1, 1, 0, 0, 0)
378
+ decade.range.max.should eq DateTime.new(1979, 12, 31, 23, 59, 59)
379
+ end
380
+
381
+ it 'should handle decade BC' do
382
+ decade_bc.range.min.should eq DateTime.new(-1979, 1, 1, 0, 0, 0)
383
+ decade_bc.range.max.should eq DateTime.new(-1970, 12, 31, 23, 59, 59)
384
+ end
385
+
386
+ it 'should handle month (31 days)' do
387
+ month_31.range.min.should eq DateTime.new(1968, 5, 1, 0, 0, 0)
388
+ month_31.range.max.should eq DateTime.new(1968, 5, 31, 23, 59, 59)
389
+ end
390
+
391
+ it 'should handle month (30 days)' do
392
+ month_30.range.min.should eq DateTime.new(1968, 6, 1, 0, 0, 0)
393
+ month_30.range.max.should eq DateTime.new(1968, 6, 30, 23, 59, 59)
394
+ end
395
+
396
+ it 'should handle month (february and leap year)' do
397
+ month_leap.range.min.should eq DateTime.new(2000, 2, 1, 0, 0, 0)
398
+ month_leap.range.max.should eq DateTime.new(2000, 2, 29, 23, 59, 59)
399
+ end
400
+
401
+ it 'should handle day' do
402
+ day.range.min.should eq DateTime.new(1956, 6, 18, 0, 0, 0)
403
+ day.range.max.should eq DateTime.new(1956, 6, 18, 23, 59, 59)
404
+ end
61
405
  end
@@ -1,19 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Wikidata do
4
+ let(:options) {
5
+ { request: { timeout: 10 } }
6
+ }
4
7
  let(:builder) {
5
- -> (builder) {
6
- builder.options[:request] = {
7
- timeout: 10,
8
- open_timeout: 2
9
- }
10
- builder.use :excon
11
- }
8
+ -> (builder) { builder.use :excon }
12
9
  }
13
10
  it 'should be configurable' do
14
11
  Wikidata.configure do |c|
12
+ c.options = options
15
13
  c.faraday = builder
16
14
  end
15
+ Wikidata.options.should be options
17
16
  Wikidata.faraday.should be builder
18
17
  end
19
18
  end
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency("faraday", "~> 0.9")
19
19
  s.add_dependency("faraday_middleware", "~> 0.9")
20
- s.add_dependency("excon", "~> 0.40")
21
20
  s.add_dependency("hashie", "~> 3.3")
21
+ s.add_development_dependency("excon", "~> 0.40")
22
22
  s.add_development_dependency("rspec", "~> 3.1")
23
23
  s.add_development_dependency("webmock", "~> 1.18")
24
24
  s.add_development_dependency("vcr", "~> 2.9")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikidata-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kévin Lacointe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
- name: excon
42
+ name: hashie
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.40'
47
+ version: '3.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.40'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: hashie
56
+ name: excon
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.3'
62
- type: :runtime
61
+ version: '0.40'
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.3'
68
+ version: '0.40'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement