aranha-parsers 0.3.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5dea73c22dac3845360b773ca5b07d3c122dbc5d108c1e24c9bd778187aedd3
4
- data.tar.gz: 836cae17dea5908018ca41e0a73566bebc35c2df67709b0c8ea2ea3509eaaeb9
3
+ metadata.gz: 0ca626da7b2bf7b1550304656001fef47dbf0446605452c985ffbdbd22509d6a
4
+ data.tar.gz: 4816fa1dbaaba92824cbdd770e5a53c9f23c95498623e923a5f04483f9c056da
5
5
  SHA512:
6
- metadata.gz: 199a2471fd78740fa54ef4f31446e8ff7f4ea74ea03d32328a5b9ee56ab99be31db87c217a544d070ce5d743cab3211847d570363d41acbe820169031a6b2715
7
- data.tar.gz: b4a9d90a266fedd2a11d497565d0ac9a10295f8ce87835689d10ab4a71b5c0bae4e2d654afe0089a9dfe190861b0bc77d77f26bcac188b772b05dc491d18b660
6
+ metadata.gz: 35e9cc36f3214baa7424ca5c175459c43a3fd0a36ee00bd236e9fea46e815e563b626d19d25c899e1bb7e92e8c5fe9427272280958a4761da1bf642c65739331
7
+ data.tar.gz: 4019fb80927d609da1a9d44ea11d42668004f4708e50745937a8d4e453569fe0fae67c657e891f12bd29ea8283e374dba68cfb2ee75d98dc9b7c6eaf20be7632
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+
3
5
  module Aranha
4
6
  module Parsers
5
- require 'aranha/parsers/base'
6
- require 'aranha/parsers/html'
7
- require 'aranha/parsers/invalid_state_exception'
8
- require 'aranha/parsers/source_address'
9
- require 'aranha/parsers/version'
7
+ ::EacRubyUtils.require_sub __FILE__
10
8
  end
11
9
  end
@@ -3,10 +3,26 @@
3
3
  require 'open-uri'
4
4
  require 'fileutils'
5
5
  require 'aranha/parsers/source_address'
6
+ require 'eac_ruby_utils/fs/temp'
6
7
 
7
8
  module Aranha
8
9
  module Parsers
9
10
  class Base
11
+ class << self
12
+ def from_content(content)
13
+ ::EacRubyUtils::Fs::Temp.on_file do |path|
14
+ path.write(content)
15
+ r = new(path.to_path)
16
+ r.content
17
+ r
18
+ end
19
+ end
20
+
21
+ def parse_content(content)
22
+ from_content(content).data
23
+ end
24
+ end
25
+
10
26
  LOG_DIR_ENVVAR = 'ARANHA_PARSERS_LOG_DIR'
11
27
 
12
28
  attr_reader :source_address
@@ -19,9 +35,11 @@ module Aranha
19
35
  delegate :url, to: :source_address
20
36
 
21
37
  def content
22
- s = source_address.content
23
- log_content(s)
24
- s
38
+ @content ||= begin
39
+ s = source_address.content
40
+ log_content(s)
41
+ s
42
+ end
25
43
  end
26
44
 
27
45
  private
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+
3
5
  module Aranha
4
6
  module Parsers
5
7
  module Html
6
- require 'aranha/parsers/html/base'
7
- require 'aranha/parsers/html/item'
8
- require 'aranha/parsers/html/item_list'
9
- require 'aranha/parsers/html/node'
8
+ ::EacRubyUtils.require_sub __FILE__
10
9
  end
11
10
  end
12
11
  end
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+
3
5
  module Aranha
4
6
  module Parsers
5
7
  module Html
6
8
  module Node
7
- require 'aranha/parsers/html/node/base'
8
- require 'aranha/parsers/html/node/default'
9
+ ::EacRubyUtils.require_sub __FILE__
9
10
  end
10
11
  end
11
12
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Patches
8
+ ::EacRubyUtils.require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ofx-parser'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Patches
8
+ module OfxParser
9
+ module OfxParser
10
+ def self.included(base)
11
+ base.class_eval do
12
+ class << self
13
+ prepend ClassMethods
14
+ end
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def build_transaction(transaction)
20
+ r = super
21
+ r.currate = (transaction / 'CURRENCY/CURRATE').inner_text
22
+ r
23
+ end
24
+ end
25
+ end
26
+
27
+ module Transaction
28
+ attr_accessor :currate, :cursym
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ require 'eac_ruby_utils/patch'
36
+
37
+ ::EacRubyUtils.patch(::OfxParser::OfxParser, ::Aranha::Parsers::Patches::OfxParser::OfxParser)
38
+ ::EacRubyUtils.patch(::OfxParser::Transaction, ::Aranha::Parsers::Patches::OfxParser::Transaction)
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
3
  require 'active_support/core_ext/module/delegation'
5
- require 'aranha/parsers/source_address/hash_http_get'
6
- require 'aranha/parsers/source_address/hash_http_post'
7
- require 'aranha/parsers/source_address/http_get'
8
- require 'aranha/parsers/source_address/file'
4
+ require 'eac_ruby_utils/require_sub'
5
+ require 'yaml'
9
6
 
10
7
  module Aranha
11
8
  module Parsers
12
9
  class SourceAddress
10
+ ::EacRubyUtils.require_sub __FILE__
11
+
13
12
  class << self
14
13
  SUBS = [
15
14
  ::Aranha::Parsers::SourceAddress::HashHttpGet,
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'active_support/core_ext/object'
4
4
  require 'active_support/core_ext/string'
5
- require 'yaml'
6
5
 
7
6
  module Aranha
8
7
  module Parsers
@@ -36,6 +35,14 @@ module Aranha
36
35
  r
37
36
  end
38
37
 
38
+ def target_files
39
+ r = []
40
+ source_target_files.each do |st|
41
+ r << st.target if st.target
42
+ end
43
+ r
44
+ end
45
+
39
46
  def target_file(basename)
40
47
  fixture_file(basename, 'target')
41
48
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'aranha/parsers/source_target_fixtures'
4
+ require 'yaml'
4
5
 
5
6
  RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable Metrics/BlockLength
6
7
  let(:spec_file) { spec_file }
@@ -9,7 +10,7 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
9
10
  expect(::File.directory?(fixtures_dir)).to be true
10
11
  end
11
12
 
12
- context 'in fixtures directory' do
13
+ context 'with fixtures directory' do
13
14
  it 'has at least one file' do
14
15
  expect(source_target_fixtures.source_target_files.count).to be > 0 # rubocop:disable Style/NumericPredicate
15
16
  end
@@ -19,8 +20,8 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
19
20
  source_target_fixtures.source_files.each do |source_file|
20
21
  sd = sort_results(source_data(source_file))
21
22
  basename = ::Aranha::Parsers::SourceTargetFixtures.source_target_basename(source_file)
22
- target_file = File.expand_path("../#{basename}.target.yaml", source_file)
23
- File.write(target_file, sd.to_yaml)
23
+ target_file = File.expand_path("../#{basename}.target#{target_file_extname}", source_file)
24
+ File.write(target_file, target_content(sd))
24
25
  end
25
26
  end
26
27
  else
@@ -28,7 +29,7 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
28
29
  source_target_fixtures.source_target_files.each do |st|
29
30
  assert_source_target_complete(st)
30
31
  sd = source_data(st.source)
31
- td = YAML.load_file(st.target)
32
+ td = target_data(st.target)
32
33
  expect(sort_results(sd)).to eq(sort_results(td))
33
34
  end
34
35
  end
@@ -45,7 +46,11 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
45
46
  end
46
47
 
47
48
  def source_data(source_file)
48
- described_class.new(source_file).data
49
+ instance = described_class.new(source_file)
50
+ return instance.data if instance.respond_to?(:data)
51
+
52
+ raise "#{instance} has no \"data\" method. You need to implement \"#{instance}.data\" or " \
53
+ "\"#{self}.source_data(source_file)\""
49
54
  end
50
55
 
51
56
  def fixtures_dir
@@ -58,4 +63,16 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
58
63
  def sort_results(results)
59
64
  results
60
65
  end
66
+
67
+ def target_data(target_file)
68
+ ::YAML.load_file(target_file)
69
+ end
70
+
71
+ def target_content(data)
72
+ data.to_yaml
73
+ end
74
+
75
+ def target_file_extname
76
+ '.yaml'
77
+ end
61
78
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aranha
4
4
  module Parsers
5
- VERSION = '0.3.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aranha-parsers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2020-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,26 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.9.10
55
+ - !ruby/object:Gem::Dependency
56
+ name: eac_ruby_utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.33'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.33.1
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.33'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.33.1
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: httpclient
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -73,19 +93,33 @@ dependencies:
73
93
  - !ruby/object:Gem::Version
74
94
  version: 2.8.3
75
95
  - !ruby/object:Gem::Dependency
76
- name: rspec
96
+ name: ofx-parser
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 1.1.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 1.1.0
109
+ - !ruby/object:Gem::Dependency
110
+ name: eac_ruby_gem_support
77
111
  requirement: !ruby/object:Gem::Requirement
78
112
  requirements:
79
113
  - - "~>"
80
114
  - !ruby/object:Gem::Version
81
- version: '3.8'
115
+ version: '0.1'
82
116
  type: :development
83
117
  prerelease: false
84
118
  version_requirements: !ruby/object:Gem::Requirement
85
119
  requirements:
86
120
  - - "~>"
87
121
  - !ruby/object:Gem::Version
88
- version: '3.8'
122
+ version: '0.1'
89
123
  description:
90
124
  email:
91
125
  executables: []
@@ -103,6 +137,8 @@ files:
103
137
  - lib/aranha/parsers/html/node/base.rb
104
138
  - lib/aranha/parsers/html/node/default.rb
105
139
  - lib/aranha/parsers/invalid_state_exception.rb
140
+ - lib/aranha/parsers/patches.rb
141
+ - lib/aranha/parsers/patches/ofx_parser.rb
106
142
  - lib/aranha/parsers/source_address.rb
107
143
  - lib/aranha/parsers/source_address/file.rb
108
144
  - lib/aranha/parsers/source_address/hash_http_get.rb
@@ -129,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
165
  - !ruby/object:Gem::Version
130
166
  version: '0'
131
167
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.7.7
168
+ rubygems_version: 3.0.8
134
169
  signing_key:
135
170
  specification_version: 4
136
171
  summary: Parsers' utilities for Ruby.