spreadsheet_to_json 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spreadsheet_to_json.rb +43 -4
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20579b86b447e68124afe0d5c2b155565022174d
4
- data.tar.gz: 0d8a1b0c58519ddf3c0ed77b97fe168932e8d622
3
+ metadata.gz: 18657291c808206aca46ce741a081cf1ecdc704c
4
+ data.tar.gz: d98ef0e39f714f8ba6bccf2507608c5ebe0f5372
5
5
  SHA512:
6
- metadata.gz: 3bab23c043dfa357b2f6a58367cd44fc0745377e4f9af7774a32c8682aa2d2e89fcac49d0c87d7d753b56cd63f3d151cff0ff3d87e8584543a319b7996572da7
7
- data.tar.gz: 3692f977b977f922b24aea7ffe5d5796d62841c8a22b14eb2dd2f6e2ad1079f3574c443af1934e18a0bcbb613fa4531c2ba11ca873b2d6372390f4d705fafd33
6
+ metadata.gz: 1e408913b1861712639a8649797661dda88cc403eb478d48cd6e2c8ffe8f12c0fe5a92c0868aaa71b3a581943a2a92f87b176b4f1ea59807ba189fb8542d593b
7
+ data.tar.gz: 430fa204dcceb6a6f741c56fbcfc4f91c6a462ed1b90ca36c8710515dda9c8bdfa817ad332b1d739533df5c53250d525e710fc145527f68bd16360c6e2fd585d
@@ -5,9 +5,38 @@ require 'json'
5
5
 
6
6
  module SpreadsheetToJson
7
7
  class << self
8
- def convert_to_json(config_path, worksheet_id=0, rows=[*2..get_spreadsheet.num_rows-2], keys_row_num)
9
- spreadsheet = get_spreadsheet(worksheet_id, config_path)
10
- rows.collect {|row_num| construct_hash(spreadsheet, keys_row_num-2, row_num-2)}.to_json
8
+ def convert_rows_by_sheet_id(config_path, worksheet_id, rows, keys_row_num)
9
+ rows_to_json(
10
+ get_sheet_by_id(worksheet_id, config_path),
11
+ rows,
12
+ keys_row_num
13
+ )
14
+ end
15
+
16
+ def convert_rows_by_sheet_name(config_path, worksheet_name, rows, keys_row_num)
17
+ rows_to_json(
18
+ get_sheet_by_name(worksheet_name, config_path),
19
+ rows,
20
+ keys_row_num
21
+ )
22
+ end
23
+
24
+ def convert_a_worksheet_by_name(config_path, worksheet_name, keys_row_num)
25
+ worksheet = get_sheet_by_name(worksheet_name, config_path)
26
+ rows_to_json(
27
+ worksheet,
28
+ [*keys_row_num+1..worksheet.num_rows],
29
+ keys_row_num
30
+ )
31
+ end
32
+
33
+ def convert_a_worksheet_by_id(config_path, worksheet_id, keys_row_num)
34
+ worksheet = get_sheet_by_id(worksheet_id, config_path)
35
+ rows_to_json(
36
+ worksheet,
37
+ [*keys_row_num+1..worksheet.num_rows],
38
+ keys_row_num
39
+ )
11
40
  end
12
41
 
13
42
  def output_json_file(content, output_path)
@@ -18,12 +47,22 @@ module SpreadsheetToJson
18
47
  end
19
48
 
20
49
  private
21
- def get_spreadsheet(worksheet_id=0, config_path)
50
+ def rows_to_json(spreadsheet, rows, keys_row_num)
51
+ rows.collect {|row_num| construct_hash(spreadsheet, keys_row_num-2, row_num-2)}.to_json
52
+ end
53
+
54
+ def get_sheet_by_id(worksheet_id=0, config_path)
22
55
  session = GoogleDrive.login_with_oauth(init_auth_token(config_path))
23
56
  session.spreadsheet_by_key(get_settings_from_yml(config_path)['spreadsheet_key']).
24
57
  worksheets[worksheet_id]
25
58
  end
26
59
 
60
+ def get_sheet_by_name(worksheet_name, config_path)
61
+ session = GoogleDrive.login_with_oauth(init_auth_token(config_path))
62
+ session.spreadsheet_by_key(get_settings_from_yml(config_path)['spreadsheet_key']).
63
+ worksheet_by_title(worksheet_name)
64
+ end
65
+
27
66
  def init_auth_token(config_path)
28
67
  config = get_settings_from_yml(config_path)
29
68
  client = OAuth2::Client.new(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_to_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xu Jianyong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  A gem to help you convert your google spreadsheet data to json format. With this gem, you can
@@ -19,7 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - lib/spreadsheet_to_json.rb
22
- homepage: ''
22
+ homepage: https://github.com/jackxu/google_spreadsheet_to_json
23
23
  licenses:
24
24
  - MIT
25
25
  metadata: {}