google-docs-table-factory 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 88ae7c8d217f19605a42423877d880af1d2326b6ce9331c149cd5fe24e2ecfd7
4
+ data.tar.gz: 924126d5b1044b889d7120212262896f970cbaceede042e87ba28e5c93612436
5
+ SHA512:
6
+ metadata.gz: 17b8de56b4e5a501aa8130d356a4b6a659d9a89b68007080c06eb99b1e09151c2474626618dab442fb20ff02f97b35d7cf53be0ff71fcb16f0dafaa5c65d851a
7
+ data.tar.gz: efe63bed09c190e618cfdc54484c82778a24dff330ce5acff88599f5c7e69e6de23d81ce8f798d6cb4de745f7df5c51a6b8622a57ee2965169edab46a6177cab
@@ -0,0 +1 @@
1
+ /Gemfile.lock
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gustavo@matias.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in google-docs-table.gemspec
4
+ gemspec
5
+
6
+ gem "minitest-reporters", "~> 1.4", group: :test
7
+
8
+ gem "pry", "~> 0.12.2", group: :test
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Gustavo Matias
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,107 @@
1
+ <p align="left">
2
+ <img width="370" src="https://user-images.githubusercontent.com/681278/71585040-1f6c9380-2b0d-11ea-90f4-68f03d37685a.jpg">
3
+ </p>
4
+
5
+ # Description
6
+
7
+ The purpose of this library is to provide simpler ways for manipulating table and its contents in Google Docs.
8
+
9
+ This solve for the difficulty myself and [a few others](https://github.com/tanaikech/node-gdoctableapp) had when attempting to manage tables on Google Docs using the Google Docs V1 API.
10
+
11
+ ## Features
12
+
13
+ - Create table with values in rows and columns
14
+
15
+ ## Some Missing Features
16
+
17
+ - Read table values
18
+ - Update table values
19
+ - Delete tables, rows and columns
20
+
21
+ ## Language Support
22
+
23
+ There are more fleshed out libraries in other languages that I found helpful when researching prior to deciding to build the first piece of the puzzle for Ruby.
24
+
25
+ - [go-gdoctableapp](https://github.com/tanaikech/go-gdoctableapp)
26
+ - [node-gdoctableapp](https://github.com/tanaikech/node-gdoctableapp)
27
+ - [gdoctableapppy](https://github.com/tanaikech/gdoctableapppy)
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'google-docs-table-factory'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install google-docs-table-factory
44
+
45
+ ## Usage
46
+
47
+ ### Create table with values in rows and columns
48
+
49
+ ```
50
+ requests = ::Google::Api::DocsV1::TableFactory.insert_table_request(
51
+ index: 1,
52
+ table_data: [
53
+ ['A1', 'B1', 'C1'],
54
+ [nil, 'B2', nil],
55
+ ['A3', 'B3', 'C3']
56
+ ]
57
+ )
58
+ ```
59
+
60
+ Will result in a structure GDocs V1 API can digest:
61
+ ```
62
+ # => requests
63
+ [
64
+ {:insert_table=>{:columns=>3, :rows=>3, :location=>{:index=>1}}}
65
+ {:insert_text=>{:location=>{:index=>23}, :text=>"C3"}}
66
+ {:insert_text=>{:location=>{:index=>21}, :text=>"B3"}}
67
+ {:insert_text=>{:location=>{:index=>19}, :text=>"A3"}}
68
+ {:insert_text=>{:location=>{:index=>14}, :text=>"B2"}}
69
+ {:insert_text=>{:location=>{:index=>9}, :text=>"C1"}}
70
+ {:insert_text=>{:location=>{:index=>7}, :text=>"B1"}}
71
+ {:insert_text=>{:location=>{:index=>5}, :text=>"A1"}}
72
+ ]
73
+ ```
74
+
75
+ And look like:
76
+ ![](https://user-images.githubusercontent.com/681278/71565771-e0f1bd00-2aa9-11ea-963e-2f48733a8222.jpg)
77
+
78
+ A full example could be:
79
+
80
+ ```
81
+ require 'google/apis/docs_v1'
82
+ require 'googleauth'
83
+
84
+ # Service Account authorization or whatever else you prefer
85
+ gdocs = ::Google::Apis::DocsV1::DocsService.new
86
+ gdoc_auth = ::Google::Auth::ServiceAccountCredentials.make_creds(scope: 'https://www.googleapis.com/auth/documents')
87
+ gdocs.authorization = gdoc_auth
88
+
89
+ # POST updates to Google Docs
90
+ file_id = 'ABC123-GoogleDocumentId-Here'
91
+ batch_request = Google::Apis::DocsV1::BatchUpdateDocumentRequest.new(requests: requests)
92
+ gdocs.batch_update_document(file_id, batch_request)
93
+ ```
94
+
95
+ ## Development
96
+
97
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
98
+
99
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gumatias/google-docs-table-factory. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+
105
+ ## Code of Conduct
106
+
107
+ Everyone interacting in the Google::Api::DocsV1::TableFactory project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gumatias/google-docs-table-factory/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "google/api/docs_v1/table_factory"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "google/api/docs_v1/table_factory/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "google-docs-table-factory"
7
+ spec.version = Google::Api::DocsV1::TableFactory::VERSION
8
+ spec.authors = ["Gustavo Matias"]
9
+ spec.email = ["gustavo@matias.love"]
10
+
11
+ spec.summary = "Ruby library for managing tables on Google Documents using the Google API"
12
+ spec.description = %q{
13
+ The purpose of this library is to provide simpler ways for manipulating table and its contents in Google Docs.
14
+
15
+ This solve for the difficulty myself and a few others had when attempting to manage tables on Google Docs using the Google Docs V1 API.
16
+ }
17
+ spec.homepage = "https://github.com/gumatias/google-docs-table-factory"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/gumatias/google-docs-table-factory"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "minitest", "~> 5.0"
34
+ end
@@ -0,0 +1,69 @@
1
+ require "google/api/docs_v1/table_factory/version"
2
+
3
+ module Google
4
+ module Api
5
+ module DocsV1
6
+ module TableFactory
7
+ class Error < StandardError; end
8
+
9
+ TABLE_CONTENT_INDEX = 4
10
+ TABLE_COLUMN_GUTTER = 2
11
+ TABLE_ROW_GUTTER = 1
12
+
13
+ def self.insert_table_request(table_data:, index:)
14
+ max_row = table_data.size
15
+ max_col = table_data.max_by(&:size).size
16
+
17
+ [
18
+ {
19
+ insert_table: {
20
+ columns: max_col,
21
+ rows: max_row,
22
+ location: {
23
+ index: index,
24
+ },
25
+ },
26
+ },
27
+ ] + request_for_insert_text(
28
+ table_data: table_data,
29
+ index: index,
30
+ max_row: max_row,
31
+ max_col: max_col,
32
+ )
33
+ end
34
+
35
+ def self.request_for_insert_text(table_data:, index:, max_row:, max_col:)
36
+ input_values = parse_input_values(
37
+ table_data: table_data,
38
+ index: index,
39
+ max_row: max_row,
40
+ max_col: max_col,
41
+ )
42
+
43
+ input_values.reverse.map do |value|
44
+ if !value[:content].nil?
45
+ { insert_text: { location: { index: value[:index] }, text: value[:content] } }
46
+ end
47
+ end.compact
48
+ end
49
+
50
+ def self.parse_input_values(table_data:, index:, max_row:, max_col:)
51
+ index += TABLE_CONTENT_INDEX
52
+ v = []
53
+ (0..(max_row - 1)).each do |row|
54
+ (0..(max_col - 1)).each do |col|
55
+ if max_row > row && max_col > col && !table_data[row][col].nil?
56
+ v.push(row: row, col: col, content: table_data[row][col], index: index)
57
+ end
58
+ index += TABLE_COLUMN_GUTTER
59
+ end
60
+
61
+ index += TABLE_ROW_GUTTER
62
+ end
63
+
64
+ v
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,9 @@
1
+ module Google
2
+ module Api
3
+ module DocsV1
4
+ module TableFactory
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-docs-table-factory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gustavo Matias
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: "\n The purpose of this library is to provide simpler ways for manipulating
56
+ table and its contents in Google Docs.\n\n This solve for the difficulty myself
57
+ and a few others had when attempting to manage tables on Google Docs using the Google
58
+ Docs V1 API.\n "
59
+ email:
60
+ - gustavo@matias.love
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - google-docs-table-factory.gemspec
74
+ - lib/google/api/docs_v1/table_factory.rb
75
+ - lib/google/api/docs_v1/table_factory/version.rb
76
+ homepage: https://github.com/gumatias/google-docs-table-factory
77
+ licenses: []
78
+ metadata:
79
+ homepage_uri: https://github.com/gumatias/google-docs-table-factory
80
+ source_code_uri: https://github.com/gumatias/google-docs-table-factory
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.10
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ruby library for managing tables on Google Documents using the Google API
101
+ test_files: []