iaa 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/*
10
+ !/tmp/humans.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install:
5
+ - gem install bundler -v 1.10.4
6
+ - sudo apt-get install pdftk -y
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
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.1.6
2
+ MAINTAINER V David Zvenyach <vladlen.zvenyach@gsa.gov>
3
+ RUN apt-get update && apt-get install pdftk -y
4
+ WORKDIR /iaa-gem
5
+ ADD . /iaa-gem
6
+ RUN gem install bundler -v 1.10.4
7
+ RUN bundle install
8
+ CMD ["/iaa-gem/bin/console"]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iaa.gemspec
4
+ gemspec
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
+ [![Build Status](https://travis-ci.org/18F/iaa-gem.svg)](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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ iaa:
2
+ build: .
3
+ volumes:
4
+ - .:/iaa-gem
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