kura 0.2.24 → 0.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 463e89c9692059ccb299e8eafd2ada9c12e41add
4
- data.tar.gz: ce52cba62de2859367b0f47bb550a1bdbf3ae842
3
+ metadata.gz: d9aa09afac8e59350c4f5fb2ea7e348c877a84d9
4
+ data.tar.gz: 8f89772e36d77680832ce10e6a2d261dbfb8dc94
5
5
  SHA512:
6
- metadata.gz: 0ac3e9c63ac16d69b6a49e76389b3d376f9ada68f8e07d9b74b8c0b5c7631f2ab65cc0349556950bc82c1334f26a631961977a3d559507e27a1443d80070cb00
7
- data.tar.gz: 9009830f5ebae2cda5cca6ef02070e295fed8f781192e45b8fc348b9185672b7db749244941c0b6648f20d6cc1978bd7e76fcc76fac679152eaf0e4a799d2a1e
6
+ metadata.gz: de549701afd6b948b7e524148386ecc1e327ddfb6a7cb54078d5879ac6e6656939d207c6eaa33c86cbaf29ddbda7c911b004b6ef4da535bab0f92b39b5a50180
7
+ data.tar.gz: 472330c158606f51a0af6bf7d2930c75862735f171ed6bd8165f8ea38283b1d411008a6dc492b515d958b2ec4b2bf14e8353a1a65d5253fe22bcb6bc162a538b
@@ -1,3 +1,9 @@
1
+ # 0.2.25
2
+
3
+ ## Enhancements
4
+
5
+ * `Kura::Client#list_tabledata` now support REPEATED/RECORD field and convert data into appropriate type of object.
6
+
1
7
  # 0.2.24
2
8
 
3
9
  ## Enhancements
@@ -229,18 +229,43 @@ module Kura
229
229
  process_error($!)
230
230
  end
231
231
 
232
- def format_tabledata(r, field_names)
232
+ def _convert_tabledata_field(x, field_info)
233
+ if x.nil? and field_info["mode"] == "NULLABLE"
234
+ return nil
235
+ end
236
+ case field_info["type"]
237
+ when "STRING"
238
+ x.to_s
239
+ when "INTEGER"
240
+ Integer(x)
241
+ when "FLOAT"
242
+ Float(x)
243
+ when "BOOLEAN"
244
+ x.to_s == "true"
245
+ when "RECORD"
246
+ _convert_tabledata_row(x, field_info["fields"])
247
+ else
248
+ x
249
+ end
250
+ end
251
+
252
+ def _convert_tabledata_row(row, schema)
253
+ (row.respond_to?(:f) ? row.f : row["f"]).zip(schema).each_with_object({}) do |(v, s), tbl|
254
+ v = JSON.parse(v.to_json)
255
+ if s["mode"] == "REPEATED"
256
+ tbl[s["name"]] = v["v"].map{|c| _convert_tabledata_field(c["v"], s) }
257
+ else
258
+ tbl[s["name"]] = _convert_tabledata_field(v["v"], s)
259
+ end
260
+ end
261
+ end
262
+
263
+ def format_tabledata(r, schema)
233
264
  {
234
265
  total_rows: r.total_rows.to_i,
235
266
  next_token: r.page_token,
236
267
  rows: (r.rows || []).map do |row|
237
- row.f.zip(field_names).each_with_object({}) do |(v, fn), tbl|
238
- if v.v.is_a?(Array)
239
- tbl[fn] = v.v.map{|c| c["v"] }
240
- else
241
- tbl[fn] = v.v
242
- end
243
- end
268
+ _convert_tabledata_row(row, schema)
244
269
  end
245
270
  }
246
271
  end
@@ -248,18 +273,18 @@ module Kura
248
273
 
249
274
  def list_tabledata(dataset_id, table_id, project_id: @default_project_id, start_index: 0, max_result: 100, page_token: nil, schema: nil, &blk)
250
275
  schema ||= table(dataset_id, table_id, project_id: project_id).schema.fields
251
- field_names = schema.map{|f| f.respond_to?(:[]) ? (f["name"] || f[:name]) : f.name }
276
+ schema = schema.map{|s| JSON.parse(s.to_json) }
252
277
 
253
278
  if blk
254
279
  @api.list_table_data(project_id, dataset_id, table_id, max_results: max_result, start_index: start_index, page_token: page_token) do |r, err|
255
280
  if r
256
- r = format_tabledata(r, field_names)
281
+ r = format_tabledata(r, schema)
257
282
  end
258
283
  blk.call(r, err)
259
284
  end
260
285
  else
261
286
  r = @api.list_table_data(project_id, dataset_id, table_id, max_results: max_result, start_index: start_index, page_token: page_token)
262
- format_tabledata(r, field_names)
287
+ format_tabledata(r, schema)
263
288
  end
264
289
  rescue
265
290
  process_error($!)
@@ -1,3 +1,3 @@
1
1
  module Kura
2
- VERSION = "0.2.24"
2
+ VERSION = "0.2.25"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chikanaga Tomoyuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-24 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client