okane 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/okane.rb +82 -0
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1412e94e73e46ebfb5c4128b0c2e76c54eb473c4b27834396a4da406d81bd311
4
- data.tar.gz: 4c5d606227a29c587b6e1e06643fb7e2f26278605122f51faaf470d1b9b9c108
3
+ metadata.gz: fd83005ad9e8bb7b76c1901a351484e96760946d579891b636f3d065afbf0bea
4
+ data.tar.gz: 57ade3800e666f6c2c847fa5dcf3cd8eca80b30e5d948364bdae8a796ec03c28
5
5
  SHA512:
6
- metadata.gz: 9c1f4fcff93c55a10f36129f0ea22b159b9271cbaee1bf13c48a6fa70d0d66c03d9fd555761e98d2d9d5e48ba98e8e7dcdac0c5537bb67fc5ade377fa5430c8b
7
- data.tar.gz: c0c225df300e43568ee7db463bc240aaf377cabd7323ff7a61679e53c61b1f8a3d4aff9f5ff7f0cc64165dd978356351c9ac6b6d3430ca51c6ff13ab692e4423
6
+ metadata.gz: 552410ed9c7ae375fc0c2010ab2942d5400d84b11cd4479ae9e9d2e380577fbf7e20b9c76a392e831d99c64d230a74b2933348705ca27ebc0b63115c883b27b2
7
+ data.tar.gz: 33770d9157f55f9ae8339494167c7fb59420176ab65c0d5506182642d576b75e598d304b39484d310d6bf56c5ad124a1568087c01f982a427f3b6aa2f2124f82
data/lib/okane.rb ADDED
@@ -0,0 +1,82 @@
1
+ module Okane
2
+ ENUMERABLE_TAGS = ["STMTTRN"]
3
+
4
+ class OFX
5
+ def self.parse(content)
6
+ lines = content.split("\n")
7
+
8
+ result = {}
9
+
10
+ tag_stack = []
11
+
12
+ lines.each do |line|
13
+ header_pattern = /(.+):(.+)/
14
+ aggregate_tag_pattern = /<(.+)>/
15
+ aggregate_closing_tag_pattern = /<\/(.+)>/
16
+ attribute_tag_pattern = /<(.+)>(.+)/
17
+ attribute_closing_tag_pattern = /<(.+)>(.+)<\/.+>/
18
+
19
+ line = line.strip
20
+
21
+ if (attribute_closing_tag_pattern.match?(line))
22
+ match = attribute_closing_tag_pattern.match(line)
23
+ tag = match[1]
24
+ value = match[2]
25
+
26
+ target_object = result.dig(*tag_stack)
27
+
28
+ if (target_object.class == Hash)
29
+ target_object[tag] = value.to_s
30
+ else
31
+ target_object.last()[tag] = value.to_s
32
+ end
33
+ elsif (attribute_tag_pattern.match?(line))
34
+ match = attribute_tag_pattern.match(line)
35
+ tag = match[1]
36
+ value = match[2]
37
+
38
+ target_object = result.dig(*tag_stack)
39
+
40
+ if (target_object.class == Hash)
41
+ target_object[tag] = value.to_s
42
+ else
43
+ target_object.last()[tag] = value.to_s
44
+ end
45
+ elsif (header_pattern.match?(line))
46
+ match = header_pattern.match(line)
47
+ result[match[1]] = match[2]
48
+ elsif (aggregate_closing_tag_pattern.match?(line))
49
+ tag_stack.pop
50
+ elsif (aggregate_tag_pattern.match?(line))
51
+ match = aggregate_tag_pattern.match(line)
52
+ tag = match[1]
53
+
54
+ if (tag_stack.count > 0)
55
+ target_object = result.dig(*tag_stack)
56
+
57
+ if (Okane::ENUMERABLE_TAGS.find_index(tag) != nil)
58
+ if (target_object[tag] == nil)
59
+ target_object[tag] = []
60
+ end
61
+
62
+ target_object[tag].append({})
63
+ else
64
+ target_object[tag] = {}
65
+ end
66
+ else
67
+ result[tag] = {}
68
+ end
69
+
70
+ tag_stack.append(tag)
71
+ elsif (line.size == 0)
72
+ # Do nothing
73
+ else
74
+ puts line
75
+ puts "No pattern found"
76
+ end
77
+ end
78
+
79
+ return result
80
+ end
81
+ end
82
+ end
metadata CHANGED
@@ -1,21 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-16 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
- files: []
18
+ files:
19
+ - lib/okane.rb
19
20
  homepage:
20
21
  licenses: []
21
22
  metadata: {}