riif 0.0.1

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 (66) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +21 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +157 -0
  8. data/Rakefile +6 -0
  9. data/lib/riif.rb +6 -0
  10. data/lib/riif/dsl/accnt.rb +15 -0
  11. data/lib/riif/dsl/base.rb +51 -0
  12. data/lib/riif/dsl/bud.rb +14 -0
  13. data/lib/riif/dsl/ctype.rb +9 -0
  14. data/lib/riif/dsl/cust.rb +51 -0
  15. data/lib/riif/dsl/emp.rb +31 -0
  16. data/lib/riif/dsl/invitem.rb +32 -0
  17. data/lib/riif/dsl/invmemo.rb +9 -0
  18. data/lib/riif/dsl/klass.rb +9 -0
  19. data/lib/riif/dsl/othername.rb +25 -0
  20. data/lib/riif/dsl/paymeth.rb +9 -0
  21. data/lib/riif/dsl/shipmeth.rb +10 -0
  22. data/lib/riif/dsl/spl.rb +29 -0
  23. data/lib/riif/dsl/terms.rb +13 -0
  24. data/lib/riif/dsl/timeact.rb +17 -0
  25. data/lib/riif/dsl/trns.rb +46 -0
  26. data/lib/riif/dsl/vend.rb +39 -0
  27. data/lib/riif/dsl/vtype.rb +9 -0
  28. data/lib/riif/iif.rb +38 -0
  29. data/lib/riif/rails/template_handler.rb +19 -0
  30. data/lib/riif/railtie.rb +16 -0
  31. data/lib/riif/version.rb +3 -0
  32. data/riif.gemspec +23 -0
  33. data/spec/fixtures/accnt.iif +2 -0
  34. data/spec/fixtures/bud.iif +2 -0
  35. data/spec/fixtures/ctype.iif +2 -0
  36. data/spec/fixtures/cust.iif +2 -0
  37. data/spec/fixtures/emp.iif +2 -0
  38. data/spec/fixtures/invitem.iif +2 -0
  39. data/spec/fixtures/invmemo.iif +2 -0
  40. data/spec/fixtures/klass.iif +2 -0
  41. data/spec/fixtures/othername.iif +2 -0
  42. data/spec/fixtures/paymeth.iif +2 -0
  43. data/spec/fixtures/shipmeth.iif +2 -0
  44. data/spec/fixtures/terms.iif +2 -0
  45. data/spec/fixtures/timeact.iif +2 -0
  46. data/spec/fixtures/trns.iif +7 -0
  47. data/spec/fixtures/vend.iif +2 -0
  48. data/spec/fixtures/vtype.iif +2 -0
  49. data/spec/riif/dsl/accnt_spec.rb +20 -0
  50. data/spec/riif/dsl/bud_spec.rb +21 -0
  51. data/spec/riif/dsl/ctype_spec.rb +17 -0
  52. data/spec/riif/dsl/cust_spec.rb +18 -0
  53. data/spec/riif/dsl/emp_spec.rb +23 -0
  54. data/spec/riif/dsl/invitem_spec.rb +19 -0
  55. data/spec/riif/dsl/invmemo_spec.rb +17 -0
  56. data/spec/riif/dsl/klass_spec.rb +18 -0
  57. data/spec/riif/dsl/othername_spec.rb +21 -0
  58. data/spec/riif/dsl/paymeth_spec.rb +17 -0
  59. data/spec/riif/dsl/shipmeth_spec.rb +17 -0
  60. data/spec/riif/dsl/terms_spec.rb +21 -0
  61. data/spec/riif/dsl/timeact_spec.rb +24 -0
  62. data/spec/riif/dsl/trns_spec.rb +49 -0
  63. data/spec/riif/dsl/vend_spec.rb +19 -0
  64. data/spec/riif/dsl/vtype_spec.rb +17 -0
  65. data/spec/spec_helper.rb +21 -0
  66. metadata +191 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: "bundle exec rspec spec"
3
+ rvm:
4
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # CHANGELOG
2
+
3
+ ## NEXT (unreleased)
4
+
5
+ ## 0.0.1
6
+
7
+ * Implement OTHERNAME
8
+ * Implement TIMEACT
9
+ * Implement TERMS
10
+ * Implement VEND
11
+ * Implement VTYPE
12
+ * Implement SHIPMETH
13
+ * Implement PAYMETH
14
+ * Implement INVMEMO
15
+ * Implement INVITEM
16
+ * Implement CTYPE
17
+ * Implement CLASS
18
+ * Implement ACCNT
19
+ * Implement EMP
20
+ * Implement CUST
21
+ * Implement TRNS and SPL
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in riif.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jun Lin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # Riif
2
+
3
+ A simple DSL to generate IIF file.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/linjunpop/riif.png?branch=master)](https://travis-ci.org/linjunpop/riif)
6
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/linjunpop/riif)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'riif'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install riif
21
+
22
+ ## Usage
23
+
24
+ ### With Rails
25
+
26
+ With a custom template handler, it works with Rails.
27
+
28
+ ```ruby
29
+ # invoices_controller.rb
30
+
31
+ class InvoicesController < ApplicationController
32
+ def show
33
+ respond_to do |format|
34
+ format.iif
35
+ format.html
36
+ end
37
+ end
38
+ end
39
+ ```
40
+
41
+ ```ruby
42
+ # show.iif.riif
43
+
44
+ iif.trns do
45
+ row do
46
+ trnsid 123
47
+ trnstype 'INVOICE'
48
+ date '8/31/1988'
49
+ accnt 'Accounts Receivable'
50
+ name 'Customer'
51
+ amount 20
52
+ docnum invoice.id
53
+ clear 'N'
54
+ toprint 'N'
55
+ addr1 'Baker'
56
+ addr2 'Customer'
57
+ end
58
+
59
+ spl do
60
+ row do
61
+ splid '777'
62
+ trnstype 'INVOICE'
63
+ date '8/31/1988'
64
+ accnt 'Income Account'
65
+ amount '-20'
66
+ clear 'N'
67
+ qnty '-2'
68
+ price 10
69
+ invitem 'Sales Item'
70
+ taxable 'N'
71
+ end
72
+ end
73
+
74
+ spl do
75
+ row do
76
+ splid '888'
77
+ end
78
+ end
79
+ end
80
+ ```
81
+
82
+ ### Without Rails
83
+
84
+ ```ruby
85
+ Riif::IIF.new.trns do
86
+ row do
87
+ trnsid 123
88
+ trnstype 'INVOICE'
89
+ date '8/31/1988'
90
+ accnt 'Accounts Receivable'
91
+ name 'Customer'
92
+ amount 20
93
+ docnum 1
94
+ clear 'N'
95
+ toprint 'N'
96
+ addr1 'Baker'
97
+ addr2 'Customer'
98
+ end
99
+
100
+ spl do
101
+ row do
102
+ splid '777'
103
+ trnstype 'INVOICE'
104
+ date '8/31/1988'
105
+ accnt 'Income Account'
106
+ amount '-20'
107
+ clear 'N'
108
+ qnty '-2'
109
+ price 10
110
+ invitem 'Sales Item'
111
+ taxable 'N'
112
+ end
113
+ end
114
+
115
+ spl do
116
+ row do
117
+ splid '888'
118
+ end
119
+ end
120
+ end
121
+ ```
122
+
123
+ Result:
124
+
125
+ ```
126
+ !TRNS TRNSID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR TOPRINT ADDR1 ADDR2 ADDR3 ADDR4 ADDR5 DUEDATE TERMS PAID SHIPDATE
127
+ !SPL SPLID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR QNTY PRICE INVITEM PAYMETH TAXABLE REIMBEXP EXTRA
128
+ !ENDTRNS
129
+ TRNS 123 INVOICE 8/31/1988 Accounts Receivable Customer 20 1 N N Baker Customer
130
+ SPL 777 INVOICE 8/31/1988 Income Account -20 N -2 10 Sales Item N
131
+ SPL 888
132
+ ENDTRNS
133
+ ```
134
+
135
+ ## Editors
136
+
137
+ ### Vim
138
+
139
+ ```VimL
140
+ au BufWinEnter,BufRead,BufNewFile *.riif set filetype=ruby
141
+ ```
142
+
143
+ ## Resources
144
+
145
+ [Use Intuit Interchange Format (.iif) files](http://support.quickbooks.intuit.com/support/articles/HOW12778)
146
+
147
+ ## Contributing
148
+
149
+ 1. Fork it
150
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
151
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
152
+ 4. Push to the branch (`git push origin my-new-feature`)
153
+ 5. Create new Pull Request
154
+
155
+ ## Changes
156
+
157
+ See [CHANGELOG.md]()
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/lib/riif.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative 'riif/version'
2
+ require_relative 'riif/iif'
3
+ require_relative 'riif/railtie' if defined?(Rails)
4
+
5
+ module Riif
6
+ end
@@ -0,0 +1,15 @@
1
+ module Riif::DSL
2
+ class Accnt < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :accnttype,
6
+ :obamount,
7
+ :desc,
8
+ :scd,
9
+ :accnum,
10
+ :extra
11
+ ]
12
+ START_COLUMN = 'ACCNT'
13
+ END_COLUMN = ''
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ module Riif::DSL
2
+ class Base
3
+
4
+ def initialize
5
+ @rows = []
6
+ @current_row = []
7
+ end
8
+
9
+ def build(&block)
10
+
11
+ instance_eval(&block)
12
+
13
+ output
14
+ end
15
+
16
+ def row(&block)
17
+ @current_row = [self.class::START_COLUMN]
18
+
19
+ instance_eval(&block)
20
+
21
+ @rows << @current_row
22
+ end
23
+
24
+ def output
25
+ {
26
+ headers: headers,
27
+ rows: rows
28
+ }
29
+ end
30
+
31
+ def headers
32
+ [
33
+ ["!#{self.class::START_COLUMN}"].concat(
34
+ self.class::HEADER_COLUMNS.map(&:upcase)
35
+ )
36
+ ]
37
+ end
38
+
39
+ def rows
40
+ @rows
41
+ end
42
+
43
+ def method_missing(method_name, *args, &block)
44
+ if self.class::HEADER_COLUMNS.include?(method_name)
45
+ @current_row[self.class::HEADER_COLUMNS.index(method_name) + 1] = args[0]
46
+ else
47
+ super
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ module Riif::DSL
2
+ class Bud < Base
3
+ HEADER_COLUMNS = [
4
+ :accnt,
5
+ :period,
6
+ :amount,
7
+ :startdate,
8
+ :class,
9
+ :customer
10
+ ]
11
+ START_COLUMN = 'BUD'
12
+ END_COLUMN = ''
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Riif::DSL
2
+ class Ctype < Base
3
+ HEADER_COLUMNS = [
4
+ :name
5
+ ]
6
+ START_COLUMN = 'CTYPE'
7
+ END_COLUMN = ''
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ module Riif::DSL
2
+ class Cust < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :baddr1,
6
+ :baddr2,
7
+ :baddr3,
8
+ :baddr4,
9
+ :baddr5,
10
+ :saddr1,
11
+ :saddr2,
12
+ :saddr3,
13
+ :saddr4,
14
+ :saddr5,
15
+ :phone1,
16
+ :phone2,
17
+ :faxnum,
18
+ :cont1,
19
+ :cont2,
20
+ :ctype,
21
+ :terms,
22
+ :taxable,
23
+ :limit,
24
+ :resalenum,
25
+ :rep,
26
+ :taxitem,
27
+ :notepad,
28
+ :salutation,
29
+ :companyname,
30
+ :firstname,
31
+ :midinit,
32
+ :lastname,
33
+ :custfld1,
34
+ :custfld2,
35
+ :custfld3,
36
+ :custfld4,
37
+ :custfld5,
38
+ :custfld6,
39
+ :custfld7,
40
+ :jobdesc,
41
+ :jobtype,
42
+ :jobstatus,
43
+ :jobstart,
44
+ :jobprojend,
45
+ :jobend,
46
+ :note
47
+ ]
48
+ START_COLUMN = 'CUST'
49
+ END_COLUMN = ''
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ module Riif::DSL
2
+ class Emp < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :init,
6
+ :addr1,
7
+ :addr2,
8
+ :addr3,
9
+ :addr4,
10
+ :addr5,
11
+ :ssno,
12
+ :phone1,
13
+ :phone2,
14
+ :notepad,
15
+ :firstname,
16
+ :midinit,
17
+ :lastname,
18
+ :salutation,
19
+ :custfld1,
20
+ :custfld2,
21
+ :custfld3,
22
+ :custfld4,
23
+ :custfld5,
24
+ :custfld6,
25
+ :custfld7,
26
+ :note
27
+ ]
28
+ START_COLUMN = 'EMP'
29
+ END_COLUMN = ''
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ module Riif::DSL
2
+ class Invitem < Base
3
+ HEADER_COLUMNS = [
4
+ :name,
5
+ :invitemtype,
6
+ :desc,
7
+ :purchasedesc,
8
+ :accnt,
9
+ :assetaccnt,
10
+ :cogsaccnt,
11
+ :price,
12
+ :cost,
13
+ :taxable,
14
+ :paymeth,
15
+ :taxvend,
16
+ :taxdist,
17
+ :toprint,
18
+ :prefvend,
19
+ :reorderpoint,
20
+ :extra,
21
+ :custfld1,
22
+ :custfld2,
23
+ :custfld3,
24
+ :custfld4,
25
+ :custfld5,
26
+ :dep_type,
27
+ :ispassedthru
28
+ ]
29
+ START_COLUMN = 'INVITEM'
30
+ END_COLUMN = ''
31
+ end
32
+ end