ofxrb 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.
- data/lib/ofx.rb +47 -0
- data/lib/ofx_102.rb +232 -0
- data/lib/ofxrb.rb +2 -0
- metadata +47 -0
data/lib/ofx.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module OFXRB
|
2
|
+
|
3
|
+
class OfxObject
|
4
|
+
|
5
|
+
# Maps humane attr_readers to the element names of the OFX specification.
|
6
|
+
def self.ofx_attrs(mapping)
|
7
|
+
mapping.each do |humane, ofx_name|
|
8
|
+
module_eval "def #{humane.to_s}; self['#{ofx_name}']; end"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Provides access to properties via their actual names in the OFX spec.
|
13
|
+
def [](key)
|
14
|
+
@properties[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
class CreditCardStatement < OfxObject
|
21
|
+
attr_reader :properties, :transactions
|
22
|
+
|
23
|
+
ofx_attrs :version => 'VERSION'
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@properties = {}
|
27
|
+
@transactions = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def stmttrn(properties)
|
31
|
+
@transactions << Transaction.new(properties)
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_missing(name, *args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class Transaction < OfxObject
|
40
|
+
ofx_attrs :amount => 'TRNAMT'
|
41
|
+
|
42
|
+
def initialize(properties)
|
43
|
+
@properties = properties
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/ofx_102.rb
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by racc 1.4.5
|
4
|
+
# from racc grammer file "ofx_102.y".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser'
|
8
|
+
|
9
|
+
|
10
|
+
require 'strscan'
|
11
|
+
#@yydebug = true
|
12
|
+
|
13
|
+
|
14
|
+
module OFXRB
|
15
|
+
|
16
|
+
class Parser102 < Racc::Parser
|
17
|
+
|
18
|
+
module_eval <<'..end ofx_102.y modeval..ida980a4d65b', 'ofx_102.y', 21
|
19
|
+
class Property
|
20
|
+
attr_accessor :key, :value
|
21
|
+
def initialize(name, value)
|
22
|
+
@key = name
|
23
|
+
@value = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Element
|
28
|
+
attr_reader :name, :properties
|
29
|
+
def initialize(start_name, elements, end_name)
|
30
|
+
raise "Element #{start_name} is being closed as #{end_name}" if start_name != end_name
|
31
|
+
@name, @properties = start_name, {}
|
32
|
+
elements.each { |e| @properties.store(e.key, e.value) if e.is_a?(Property) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def name_from_ofx(tag)
|
37
|
+
$1 if tag =~ /<\/?(\w+)>/
|
38
|
+
end
|
39
|
+
|
40
|
+
def property(val)
|
41
|
+
Property.new(name_from_ofx(val[0]), val[1])
|
42
|
+
end
|
43
|
+
|
44
|
+
# When an OFXRB::Element has been created, the current handler will receive a
|
45
|
+
# a method send where the name is the downcased name of the OFXRB::Element.
|
46
|
+
def element(val)
|
47
|
+
e = Element.new(name_from_ofx(val[0]), val[1], name_from_ofx(val[2]));
|
48
|
+
@ofx.send(e.name.downcase.to_sym, e.properties)
|
49
|
+
e
|
50
|
+
end
|
51
|
+
|
52
|
+
MATCH_TOKENS = {
|
53
|
+
:START_TAG => /<\w+>/,
|
54
|
+
:END_TAG => /<\/\w+>/,
|
55
|
+
:STRING => /[^\r\n<>:]+/,
|
56
|
+
:COLON => /:/,
|
57
|
+
}
|
58
|
+
|
59
|
+
# Implements the Racc#parse method using a StringScanner to lex
|
60
|
+
def parse(string)
|
61
|
+
@ofx = CreditCardStatement.new
|
62
|
+
|
63
|
+
@tokens, s = [], StringScanner.new(string)
|
64
|
+
until s.eos?
|
65
|
+
s.scan(/\s*/)
|
66
|
+
MATCH_TOKENS.each do |key, value|
|
67
|
+
if s.scan(value)
|
68
|
+
@tokens << [key, s.matched]
|
69
|
+
break # to consume more whitespace, move forward
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
do_parse
|
75
|
+
@ofx
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def next_token
|
80
|
+
@tokens.shift
|
81
|
+
end
|
82
|
+
..end ofx_102.y modeval..ida980a4d65b
|
83
|
+
|
84
|
+
##### racc 1.4.5 generates ###
|
85
|
+
|
86
|
+
racc_reduce_table = [
|
87
|
+
0, 0, :racc_error,
|
88
|
+
2, 7, :_reduce_none,
|
89
|
+
2, 8, :_reduce_none,
|
90
|
+
1, 8, :_reduce_none,
|
91
|
+
3, 10, :_reduce_4,
|
92
|
+
2, 9, :_reduce_5,
|
93
|
+
1, 9, :_reduce_6,
|
94
|
+
1, 11, :_reduce_none,
|
95
|
+
1, 11, :_reduce_none,
|
96
|
+
2, 13, :_reduce_9,
|
97
|
+
3, 12, :_reduce_10 ]
|
98
|
+
|
99
|
+
racc_reduce_n = 11
|
100
|
+
|
101
|
+
racc_shift_n = 19
|
102
|
+
|
103
|
+
racc_action_table = [
|
104
|
+
1, 15, 10, 10, 10, 18, 13, 6, 14, 5,
|
105
|
+
10, 1 ]
|
106
|
+
|
107
|
+
racc_action_check = [
|
108
|
+
3, 10, 3, 10, 16, 16, 5, 2, 6, 1,
|
109
|
+
11, 0 ]
|
110
|
+
|
111
|
+
racc_action_pointer = [
|
112
|
+
9, 6, 7, -2, nil, 4, 8, nil, nil, nil,
|
113
|
+
-1, 6, nil, nil, nil, nil, 0, nil, nil ]
|
114
|
+
|
115
|
+
racc_action_default = [
|
116
|
+
-11, -11, -11, -11, -3, -11, -11, -6, -7, -8,
|
117
|
+
-11, -1, -2, -4, 19, -9, -11, -5, -10 ]
|
118
|
+
|
119
|
+
racc_goto_table = [
|
120
|
+
11, 17, 4, 3, 2, 12, 17, 16 ]
|
121
|
+
|
122
|
+
racc_goto_check = [
|
123
|
+
3, 5, 4, 2, 1, 4, 5, 3 ]
|
124
|
+
|
125
|
+
racc_goto_pointer = [
|
126
|
+
nil, 4, 3, -3, 2, -10, nil, nil ]
|
127
|
+
|
128
|
+
racc_goto_default = [
|
129
|
+
nil, nil, nil, nil, nil, 7, 8, 9 ]
|
130
|
+
|
131
|
+
racc_token_table = {
|
132
|
+
false => 0,
|
133
|
+
Object.new => 1,
|
134
|
+
:STRING => 2,
|
135
|
+
:COLON => 3,
|
136
|
+
:START_TAG => 4,
|
137
|
+
:END_TAG => 5 }
|
138
|
+
|
139
|
+
racc_use_result_var = true
|
140
|
+
|
141
|
+
racc_nt_base = 6
|
142
|
+
|
143
|
+
Racc_arg = [
|
144
|
+
racc_action_table,
|
145
|
+
racc_action_check,
|
146
|
+
racc_action_default,
|
147
|
+
racc_action_pointer,
|
148
|
+
racc_goto_table,
|
149
|
+
racc_goto_check,
|
150
|
+
racc_goto_default,
|
151
|
+
racc_goto_pointer,
|
152
|
+
racc_nt_base,
|
153
|
+
racc_reduce_table,
|
154
|
+
racc_token_table,
|
155
|
+
racc_shift_n,
|
156
|
+
racc_reduce_n,
|
157
|
+
racc_use_result_var ]
|
158
|
+
|
159
|
+
Racc_token_to_s_table = [
|
160
|
+
'$end',
|
161
|
+
'error',
|
162
|
+
'STRING',
|
163
|
+
'COLON',
|
164
|
+
'START_TAG',
|
165
|
+
'END_TAG',
|
166
|
+
'$start',
|
167
|
+
'root',
|
168
|
+
'headers',
|
169
|
+
'elements',
|
170
|
+
'key_value_pair',
|
171
|
+
'element',
|
172
|
+
'closed_element',
|
173
|
+
'one_line_element']
|
174
|
+
|
175
|
+
Racc_debug_parser = false
|
176
|
+
|
177
|
+
##### racc system variables end #####
|
178
|
+
|
179
|
+
# reduce 0 omitted
|
180
|
+
|
181
|
+
# reduce 1 omitted
|
182
|
+
|
183
|
+
# reduce 2 omitted
|
184
|
+
|
185
|
+
# reduce 3 omitted
|
186
|
+
|
187
|
+
module_eval <<'.,.,', 'ofx_102.y', 5
|
188
|
+
def _reduce_4( val, _values, result )
|
189
|
+
@ofx.properties.store(val[0], val[2])
|
190
|
+
result
|
191
|
+
end
|
192
|
+
.,.,
|
193
|
+
|
194
|
+
module_eval <<'.,.,', 'ofx_102.y', 7
|
195
|
+
def _reduce_5( val, _values, result )
|
196
|
+
result << val[1]
|
197
|
+
result
|
198
|
+
end
|
199
|
+
.,.,
|
200
|
+
|
201
|
+
module_eval <<'.,.,', 'ofx_102.y', 8
|
202
|
+
def _reduce_6( val, _values, result )
|
203
|
+
result = [val[0]]
|
204
|
+
result
|
205
|
+
end
|
206
|
+
.,.,
|
207
|
+
|
208
|
+
# reduce 7 omitted
|
209
|
+
|
210
|
+
# reduce 8 omitted
|
211
|
+
|
212
|
+
module_eval <<'.,.,', 'ofx_102.y', 11
|
213
|
+
def _reduce_9( val, _values, result )
|
214
|
+
result = property(val)
|
215
|
+
result
|
216
|
+
end
|
217
|
+
.,.,
|
218
|
+
|
219
|
+
module_eval <<'.,.,', 'ofx_102.y', 12
|
220
|
+
def _reduce_10( val, _values, result )
|
221
|
+
result = element(val)
|
222
|
+
result
|
223
|
+
end
|
224
|
+
.,.,
|
225
|
+
|
226
|
+
def _reduce_none( val, _values, result )
|
227
|
+
result
|
228
|
+
end
|
229
|
+
|
230
|
+
end # class Parser102
|
231
|
+
|
232
|
+
end # module OFXRB
|
data/lib/ofxrb.rb
ADDED
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: ofxrb
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-08-08 00:00:00 -04:00
|
8
|
+
summary: ofxrb is a pure-Ruby OFX (Open Financial Exchange) library
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: adam@thewilliams.ws
|
12
|
+
homepage: http://ofxrb.rubyforge.org
|
13
|
+
rubyforge_project: ofxrb
|
14
|
+
description:
|
15
|
+
autorequire: ofxrb
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.1
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Adam Williams, Austin Taylor
|
30
|
+
files:
|
31
|
+
- lib/ofx.rb
|
32
|
+
- lib/ofx_102.rb
|
33
|
+
- lib/ofxrb.rb
|
34
|
+
test_files: []
|
35
|
+
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
extra_rdoc_files: []
|
39
|
+
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
requirements: []
|
45
|
+
|
46
|
+
dependencies: []
|
47
|
+
|