dxcalc 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0065c95f05e64c726e2f26724533ed2f0e4bf22c
4
+ data.tar.gz: 57c621a5aef22a4b2b861bd973e0312a43220636
5
+ SHA512:
6
+ metadata.gz: c251f947639ac0e6b50f9a461fd9b74bded37d9a4c04393b7f1a40c127844a2cf132a91b27bb54638bec64141b7084a506d3cf00ae6a7738f18653a927c14524
7
+ data.tar.gz: c3f0d56983499d948c77ca2c8cd7718b314bf3d4fed1467b1852ab4228e577f489d6bd1fe40126549fd18c59b6447224d7659dd9be814e45baeb7d4ca3cf5720
Binary file
Binary file
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: dxcalc.rb
4
+
5
+ require 'dynarex'
6
+
7
+
8
+ class DxCalc
9
+
10
+ def initialize(src: nil, sheet: nil)
11
+ parse(sheet, src)
12
+ end
13
+
14
+ def parse(s, dx)
15
+
16
+ raw_summary, raw_body = s.strip.split(/----*/)
17
+ lines = raw_summary.gsub(/\n\n+/,"\n").lines
18
+ declaration = lines.shift
19
+ summary = lines.map {|x| x.match(/^(\w+):\s*([^\n]+)/).captures}.to_h
20
+
21
+ sheet_summary = lines.map do |x|
22
+ cols = x.match(/^(\w+):\s*([^\n]+)/).captures
23
+ [cols[0].to_sym, cols[1]]
24
+ end.to_h
25
+
26
+ body = raw_body.lstrip.lines.map {|x| x.chomp.split(/\s+#\s+/) }
27
+
28
+ fields = declaration[/[^\(]+(?=\))/].split(/,\s*/).map(&:to_sym)
29
+ columns = fields.zip(body).to_h
30
+
31
+ a = dx.to_a
32
+ dx_keys = a.first.keys
33
+
34
+ @h = fields.inject({}) do |r,field|
35
+
36
+ # look for the field in the following order
37
+ # 1. data src
38
+ # 2. summary
39
+ # 3. sheet schema
40
+
41
+ val = if dx_keys.include? field
42
+
43
+ #a.map {|x| x[field].to_f }
44
+ a.map {|x| x[field] }
45
+
46
+ elsif sheet_summary.has_key? field
47
+ columns[field].first
48
+ end
49
+
50
+ r.merge(field =>val)
51
+ end
52
+
53
+ end
54
+
55
+ def to_h
56
+ @h
57
+ end
58
+
59
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dxcalc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE3MDIyNzEzMDIyMFoXDTE4MDIyNzEzMDIyMFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAMgIlhpyAjMleLbtyk6UkEHXFJlpwOHoqT46Mh98WMvHO4ddKOSqHhWBYZ09
19
+ Tn1vGm1GzTeAxmevSfq0ynfXJlRNSmtIcPiL41Q9kMyra4Gz7Ug82nf7dPys5v2c
20
+ u19Dl9tfaF9CBrDlykN4LX2yzQ7C+A7Ae4404S7mk+RM3tjPHmZGZOzpI+tabXWU
21
+ gwt4En9b38F/GU80CjSuxkonlal5MY430k5Uih+NUc/MyMr0OuX6ylwauKLcULvZ
22
+ w9aISxrPnN8AVxSRia9mZdKegvqUAWMuutEvu2YWcXSgkU/H+dXI4uww83US6MKJ
23
+ 1tbYLDuBdZgo0m83RkxzFoUbDSsCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUTevAzbB7AP00Dytq5M/JEa0kafswJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAj7MJIMrZ
27
+ g8cy6PrtoFKnxyd4YLYU12Rq7BcKQO9oqmDx9ocVczuZ/Yv0i30/J95UMofq+TJW
28
+ lJaOHaVTk8BnTrw9SR6Jmq1DOw333i1E+KiZa2j0H7EiLl6tigHRumZvyt0FcK6x
29
+ 5W2SwSVs/6KnX7PXzLSQfAEBXWBDLz0Zxs5SqpB0fwnoZnOcI8tEzEsxglxufJX3
30
+ 0wXjUua6kiQQZl8FdLs7h8C/fT3Vbqw0G3HcOC51sBaBHkQ9MZdE0bId54BdGicB
31
+ f2AKXm2ZgCB0qkEqfGTzrUthmstb2Xcr92Edh+7h5DGD61+Cd3dI80qOK7O/nCzd
32
+ 35OzBruYrF1DrQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2017-02-27 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: dynarex
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.7'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.7.20
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.7'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.7.20
56
+ description:
57
+ email: james@jamesrobertson.eu
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/dxcalc.rb
63
+ homepage: https://github.com/jrobertson/dxcalc
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: dxcalc
87
+ test_files: []
@@ -0,0 +1 @@
1
+ -Y� ������)��| �P�u �