iaa 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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CONTRIBUTING.md +15 -0
- data/Dockerfile +8 -0
- data/Gemfile +4 -0
- data/LICENSE.md +31 -0
- data/README.md +98 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/docker-compose.yml +4 -0
- data/iaa.gemspec +36 -0
- data/lib/base_form.rb +80 -0
- data/lib/form_7600a.rb +392 -0
- data/lib/form_7600b.rb +1608 -0
- data/lib/iaa/version.rb +3 -0
- data/lib/iaa.rb +11 -0
- data/lib/mappings/7600A.json +383 -0
- data/lib/mappings/7600B.json +1447 -0
- data/lib/pdfs/7600A.pdf +0 -0
- data/lib/pdfs/7600B.pdf +0 -0
- data/tmp/humans.txt +0 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bcd9a53843a589857b720adf9e28fe794bf686ba
|
4
|
+
data.tar.gz: e2217c2af2632269e6400c21976b981752ff582d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54e98206a7bd0cebbdfa31ccd66e17774ccbf21f5ac6f1d0dd7dfd46ddee043cf6dff3d91b9812f97698bb7fc9d1819725e3d9c4d6330282e40f13144dec3350
|
7
|
+
data.tar.gz: 62ae37a08a5f2cbeec6f87a4f58e777c4dfd0112be462df682a13b0519659533eaf9388fad4b36c516e4bca4ace8eb6f9a8e93c9eb114d90eea618c751f545ae
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
## Welcome!
|
2
|
+
|
3
|
+
We're so glad you're thinking about contributing to an 18F open source project! If you're unsure or afraid of anything, just ask or submit the issue or pull request anyways. The worst that can happen is that you'll be politely asked to change something. We appreciate any sort of contribution, and don't want a wall of rules to get in the way of that.
|
4
|
+
|
5
|
+
Before contributing, we encourage you to read our CONTRIBUTING policy (you are here), our LICENSE, and our README, all of which should be in this repository. If you have any questions, or want to read more about our underlying policies, you can consult the 18F Open Source Policy GitHub repository at https://github.com/18f/open-source-policy, or just shoot us an email/official government letterhead note to [18f@gsa.gov](mailto:18f@gsa.gov).
|
6
|
+
|
7
|
+
## Public domain
|
8
|
+
|
9
|
+
This project is in the public domain within the United States, and
|
10
|
+
copyright and related rights in the work worldwide are waived through
|
11
|
+
the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
|
12
|
+
|
13
|
+
All contributions to this project will be released under the CC0
|
14
|
+
dedication. By submitting a pull request, you are agreeing to comply
|
15
|
+
with this waiver of copyright interest.
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
As a work of the United States Government, this project is in the
|
2
|
+
public domain within the United States.
|
3
|
+
|
4
|
+
Additionally, we waive copyright and related rights in the work
|
5
|
+
worldwide through the CC0 1.0 Universal public domain dedication.
|
6
|
+
|
7
|
+
## CC0 1.0 Universal Summary
|
8
|
+
|
9
|
+
This is a human-readable summary of the [Legal Code (read the full text)](https://creativecommons.org/publicdomain/zero/1.0/legalcode).
|
10
|
+
|
11
|
+
### No Copyright
|
12
|
+
|
13
|
+
The person who associated a work with this deed has dedicated the work to
|
14
|
+
the public domain by waiving all of his or her rights to the work worldwide
|
15
|
+
under copyright law, including all related and neighboring rights, to the
|
16
|
+
extent allowed by law.
|
17
|
+
|
18
|
+
You can copy, modify, distribute and perform the work, even for commercial
|
19
|
+
purposes, all without asking permission.
|
20
|
+
|
21
|
+
### Other Information
|
22
|
+
|
23
|
+
In no way are the patent or trademark rights of any person affected by CC0,
|
24
|
+
nor are the rights that other persons may have in the work or in how the
|
25
|
+
work is used, such as publicity or privacy rights.
|
26
|
+
|
27
|
+
Unless expressly stated otherwise, the person who associated a work with
|
28
|
+
this deed makes no warranties about the work, and disclaims liability for
|
29
|
+
all uses of the work, to the fullest extent permitted by applicable law.
|
30
|
+
When using or citing the work, you should not imply endorsement by the
|
31
|
+
author or the affirmer.
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
[](https://travis-ci.org/18F/iaa-gem)
|
2
|
+
|
3
|
+
# IAA
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Dependencies (other than standard Ruby/bundler):
|
8
|
+
|
9
|
+
- `pdftk`. Get it [here](https://www.pdflabs.com/tools/pdftk-server/).
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'iaa'
|
15
|
+
```
|
16
|
+
|
17
|
+
To use the latest and greatest:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'iaa', github: '18F/iaa-gem', branch: 'master'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
$ bundle
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
This gem makes available two classes, `IAA::Form7600A` and `IAA::Form7600B`.
|
32
|
+
|
33
|
+
### Open and read an existing IAA Form 7600A or 7600B
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
form = IAA::Form7600A.new(pdf_path: 'path/to/7600A.pdf')
|
37
|
+
form.start_date #=> "05-20-2015"
|
38
|
+
form.end_date #> "06-20-2015"
|
39
|
+
# ... etc
|
40
|
+
```
|
41
|
+
|
42
|
+
### Edit and save an IAA Form 7600A or 7600B
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
form.start_date = "05-21-2015"
|
46
|
+
form.save('/path/to/save/destination')
|
47
|
+
```
|
48
|
+
|
49
|
+
Note: the default directory to save is the "tmp" directory within the iaa-gem directory.
|
50
|
+
|
51
|
+
### Start from a blank IAA Form 7600A or 7600B
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
form2 = IAA::Form7600A.new
|
55
|
+
form2.start_date = "07-07-2016"
|
56
|
+
form.save('/path/to/save/destination')
|
57
|
+
```
|
58
|
+
|
59
|
+
See `lib/form_7600a.rb` and `lib/form_7600b` for all getter and setter methods.
|
60
|
+
|
61
|
+
### mappings.json
|
62
|
+
|
63
|
+
This repo provides a JSON file for each form (`lib/mappings/7600A.json` and `lib/mappings/7600B.json`) of all form fields including their types and possible values (e.g. for radio buttons and checkboxes). This could be used to map objects in other languages to the IAA Form 7600A.
|
64
|
+
|
65
|
+
## Docker Compose Usage
|
66
|
+
|
67
|
+
1. Make sure that [Docker Compose](https://docs.docker.com/compose/install/) is installed.
|
68
|
+
2. Navigate to iaa-gem directory and run `docker-compose build`.
|
69
|
+
3. Run `docker-compose run iaa`.
|
70
|
+
|
71
|
+
## Caveats
|
72
|
+
|
73
|
+
Currently, the following fields cannot be set:
|
74
|
+
|
75
|
+
### Form 7600A
|
76
|
+
|
77
|
+
- gt_and_c_number
|
78
|
+
- general_explanation_overhead_fees_and_charges
|
79
|
+
- number_of_days_this_iaa_may_be_terminated
|
80
|
+
|
81
|
+
### Form 7600B
|
82
|
+
|
83
|
+
- gt_and_c_number
|
84
|
+
- requesting_agency_a
|
85
|
+
- servicing_agency_a
|
86
|
+
- overhead_fees_and_charges
|
87
|
+
|
88
|
+
See https://github.com/18F/iaa-gem/issues/6.
|
89
|
+
|
90
|
+
## Development
|
91
|
+
|
92
|
+
After checking out the repo, run `gem install bundler && bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
93
|
+
|
94
|
+
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).
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/18F/iaa-gem.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "iaa"
|
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
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
data/iaa.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iaa/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iaa"
|
8
|
+
spec.version = IAA::VERSION
|
9
|
+
spec.authors = ["Alan deLevie", "V. David Zvenyach"]
|
10
|
+
spec.email = ["alan.delevie@gsa.gov"]
|
11
|
+
spec.summary = %q{Programatically fills PDF to produce Inter-Agency Agreements (IAAs)}
|
12
|
+
spec.description = %q{Helps you create IAAs}
|
13
|
+
spec.homepage = "https://github.com/18f/iaa-gem"
|
14
|
+
spec.license = "See LICENSE.md"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "pdf-forms"
|
30
|
+
spec.add_runtime_dependency "cliver"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
spec.add_development_dependency "pry"
|
36
|
+
end
|
data/lib/base_form.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'pdf_forms'
|
2
|
+
require 'json'
|
3
|
+
require 'pry'
|
4
|
+
require 'cliver'
|
5
|
+
|
6
|
+
module IAA
|
7
|
+
class BaseForm
|
8
|
+
def init_pdftk(pdftk_path)
|
9
|
+
PdfForms.new(pdftk_path || Cliver.detect('pdftk'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_mapper_fields(path)
|
13
|
+
JSON.parse(File.read(path))
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_fields_from_pdf!(pdf_path, pdftk, form_object)
|
17
|
+
return if pdf_path.nil?
|
18
|
+
fields = pdftk.get_fields(pdf_path)
|
19
|
+
fields.each do |field|
|
20
|
+
value = field.value rescue nil
|
21
|
+
form_object.set_attr(field.name, value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(pdf_path: nil, pdftk_path: nil)
|
26
|
+
@fields = get_mapper_fields(self.class.mapper_path)
|
27
|
+
@pdftk = init_pdftk(pdftk_path)
|
28
|
+
@save_filename = nil
|
29
|
+
@fill_values = {}
|
30
|
+
load_fields_from_pdf!(pdf_path, @pdftk, self)
|
31
|
+
@pdf_path = pdf_path || self.class.default_pdf_path
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_fields
|
35
|
+
@pdftk.get_fields(@pdf_path).map do |field|
|
36
|
+
{
|
37
|
+
"name" => field.name,
|
38
|
+
"options" => field.options,
|
39
|
+
"type" => field.type,
|
40
|
+
"value" => field.value
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def read_field(field_name)
|
46
|
+
read_fields.find {|f| f["name"] == field_name}["value"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def fill_attributes
|
50
|
+
@fill_values
|
51
|
+
end
|
52
|
+
|
53
|
+
def filename
|
54
|
+
@save_filename
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_attr(field, value)
|
58
|
+
@fill_values[field] = value
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_attr(field)
|
62
|
+
@fill_values[field]
|
63
|
+
end
|
64
|
+
|
65
|
+
def save(save_path='tmp')
|
66
|
+
filename = "#{save_path}/#{self.class.form_name}_#{Time.now.to_i}.pdf"
|
67
|
+
@pdftk.fill_form @pdf_path, filename, @fill_values
|
68
|
+
@filename = filename
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.mapper_path
|
72
|
+
"lib/mappings/#{self.form_name}.json"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.default_pdf_path
|
76
|
+
"lib/pdfs/#{self.form_name}.pdf"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|