client_bank_exchange 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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/client_bank_exchange.rb +87 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92621e68a03565d0b587d1c7b954298ffbf58f16
4
+ data.tar.gz: 0b7f97f49af52dbdae699e10b9c0dd61df105902
5
+ SHA512:
6
+ metadata.gz: 89d08d70a5fa54e68f77b04ac4e8bc40d9748bc304d97cb1d4248c867593b9ae3ea1cb28cc513a6afa9d285ca264a96cb79da679c29bf93a82fd2f6ef96efba1
7
+ data.tar.gz: 9f369100b8cecbc1281d4845164288026f752217f75e555a5b71d6150bac2193559dee823559645bc369298973f13da5d7c0388c13ae054d0c9cc1d4fa5c5b0c
@@ -0,0 +1,87 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ module ClientBankExchange
5
+ def self.parse_file path
6
+ self.parse File.read(path)
7
+ end
8
+
9
+ def self.parse content
10
+ result = {
11
+ errors: [],
12
+ general: {},
13
+ remainings: {},
14
+ filters: {},
15
+ documents: []
16
+ }
17
+
18
+ if content.start_with? '1CClientBankExchange'
19
+ # parse general info (key=value)
20
+ [
21
+ :ВерсияФормата, :Кодировка,
22
+ :Отправитель, :Получатель,
23
+ :ДатаСоздания, :ВремяСоздания
24
+ ].each do |key|
25
+ /#{key}=(.*)/.match(content) do |match|
26
+ result[:general][key] = match[1]
27
+ end
28
+ end
29
+
30
+ hash_value_to_date result[:general], :ДатаСоздания
31
+ hash_value_to_time result[:general], :ВремяСоздания
32
+
33
+ # parse remainings
34
+ /СекцияРасчСчет([\s\S]*?)\sКонецРасчСчет/.match(content) do |match|
35
+ # remainings properties (key=value)
36
+ match[1].scan(/(.*)=(.*)/) { |k, v| result[:remainings][k.to_sym] = v }
37
+
38
+ # normalize
39
+ hash_value_to_date result[:remainings], :ДатаНачала
40
+ hash_value_to_date result[:remainings], :ДатаКонца
41
+ hash_value_to_f result[:remainings], :НачальныйОстаток
42
+ hash_value_to_f result[:remainings], :ВсегоПоступило
43
+ hash_value_to_f result[:remainings], :ВсегоСписано
44
+ hash_value_to_f result[:remainings], :КонечныйОстаток
45
+ end
46
+
47
+ # parse documents
48
+ regexp_document = /СекцияДокумент=(.*)\s([\s\S]*?)\sКонецДокумента/
49
+ result[:documents] = content.scan(regexp_document).map do |doc|
50
+ # document type
51
+ document = { СекцияДокумент: doc[0] }
52
+
53
+ # document properties (key=value)
54
+ doc[1].scan(/(.*)=(.*)/) { |k, v| document[k.to_sym] = v }
55
+
56
+ # normalize
57
+ hash_value_to_i document, :Номер
58
+ hash_value_to_date document, :Дата
59
+ hash_value_to_f document, :Сумма
60
+
61
+ document
62
+ end
63
+ else
64
+ result[:errors] << 'Wrong format: 1CClientBankExchange not found'
65
+ end
66
+
67
+ result
68
+ end
69
+
70
+ private
71
+
72
+ def self.hash_value_to_date hash, key
73
+ hash[key] = Date.parse(hash[key]) if hash[key]
74
+ end
75
+
76
+ def self.hash_value_to_time hash, key
77
+ hash[key] = Time.parse(hash[key]) if hash[key]
78
+ end
79
+
80
+ def self.hash_value_to_i hash, key
81
+ hash[key] = hash[key].to_i if hash[key]
82
+ end
83
+
84
+ def self.hash_value_to_f hash, key
85
+ hash[key] = hash[key].to_f if hash[key]
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: client_bank_exchange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Zharikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Format specification: http://v8.1c.ru/edi/edi_stnd/100/101.htm'
14
+ email: andrey@zharikov.pro
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/client_bank_exchange.rb
20
+ homepage: https://github.com/zharikovpro/client_bank_exchange
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Import and export for 1CClientBankExchange v1.02 file format
44
+ test_files: []