ehbrs-tools 0.16.0 → 0.16.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/tools/version.rb +1 -1
  3. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  4. data/vendor/aranha-parsers/Gemfile +5 -0
  5. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  6. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  7. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  8. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  9. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  10. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  11. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  12. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  13. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  14. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  15. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  16. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  17. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  18. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  19. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  20. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  21. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  22. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  23. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  24. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +70 -0
  25. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  26. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  27. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  28. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  29. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  30. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  31. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  32. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  33. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  34. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  35. data/vendor/eac_cli/lib/eac_cli/definition.rb +14 -4
  36. data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
  37. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +15 -2
  38. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +4 -63
  39. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  43. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
  44. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  45. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  47. metadata +38 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c933ef15a718774ec5c1a1f2d4915da05a21d76df979e12a901ed036b9794877
4
- data.tar.gz: 4b942fb2711d4a9dfc3ff5f89b1ed73167124b0f3974ab1f023ddd3e68724538
3
+ metadata.gz: 802c81117166172af4ea59889f51ca8fa22e9619c3db5c3c6cea3facefd67816
4
+ data.tar.gz: 524a0c12d36e164f7530653ace84b229d3c90b382bd148fc2dabdf51611881e4
5
5
  SHA512:
6
- metadata.gz: 5a07de2b1b7ec7208b46b14b19e84a69e43a2c3c1d9b29b2e8cebbb253324efbff9390464a26c2d6289542bf5cc41aac08ca5cf64a26a103f5d1ae8b7c2f6d82
7
- data.tar.gz: e456a371d70caa2e7bf9a8c34adc950f413e4673dce6f0666b7eed406cf184ae9a042d9cb7e3e7a7fd306f7eaf7ccbd6304c7e778ae925f1999e2f09e3e995e6
6
+ metadata.gz: 8704fd788c833ebd36f2c3bab048855993cba2fbe29555040027965195d698eba76d2e36d77ded10672bf50027b441af11d9732ce8bf8dde6fb821623155ea1e
7
+ data.tar.gz: 45fa1972f370a98e24424a55ff81b964525799512e6d288fbde84996c5d36540cf368491de00423036f327cc5470889fae2ea0fcf52f40eb29fdfc736275a797
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ehbrs
4
4
  module Tools
5
- VERSION = '0.16.0'
5
+ VERSION = '0.16.1'
6
6
  end
7
7
  end
@@ -11,7 +11,11 @@ module Ehbrs
11
11
  enable_simple_cache
12
12
  common_constructor :output
13
13
 
14
- FILE_DISC_TYPE_PATTERN = %r{\A(\S+)/(\S+)\s+&\s+(\S+)\z}.freeze
14
+ # WIA/WII (v1.00,LZMA2.7@100) & Wii
15
+ # ISO/WII & Wii
16
+ # WBFS/WII & Wii
17
+ # ISO/GC & GameCube
18
+ FILE_DISC_TYPE_PATTERN = %r{\A(\S+)/(\S+)\s+(?:\(([^\)]+)\)\s+)?&\s+(\S+)\z}.freeze
15
19
 
16
20
  private
17
21
 
@@ -42,10 +46,11 @@ module Ehbrs
42
46
  end
43
47
 
44
48
  def parse_file_disc_type(value)
45
- FILE_DISC_TYPE_PATTERN
46
- .match(value)
47
- .if_present { |m| { type: m[1], platform_acronym: m[2], platform_name: m[3] } }
48
- .if_blank { raise "\"#{FILE_DISC_TYPE_PATTERN}\" does not match \"#{value}\"" }
49
+ r = FILE_DISC_TYPE_PATTERN.match(value).if_present do |m|
50
+ { type: m[1], platform_acronym: m[2], type_extra: m[3],
51
+ platform_name: m[4] }
52
+ end
53
+ r.if_blank { raise "\"#{FILE_DISC_TYPE_PATTERN}\" does not match \"#{value}\"" }
49
54
  end
50
55
 
51
56
  def parse_disc_part_ids(value)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'aranha/parsers/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'aranha-parsers'
9
+ s.version = ::Aranha::Parsers::VERSION
10
+ s.authors = ['Esquilo Azul Company']
11
+ s.summary = 'Parsers\' utilities for Ruby.'
12
+
13
+ s.files = Dir['{lib}/**/*', 'Gemfile']
14
+
15
+ s.add_dependency 'activesupport', '>= 4.0.0'
16
+ s.add_dependency 'addressable', '~> 2.7'
17
+ s.add_dependency 'curb', '~> 0.9.10'
18
+ s.add_dependency 'eac_ruby_utils', '~> 0.33', '>= 0.33.1'
19
+ s.add_dependency 'httpclient', '~> 2.8', '>= 2.8.3'
20
+ s.add_dependency 'ofx-parser', '~> 1.1.0'
21
+
22
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1'
23
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ ::EacRubyUtils.require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+ require 'fileutils'
5
+ require 'aranha/parsers/source_address'
6
+ require 'eac_ruby_utils/fs/temp'
7
+
8
+ module Aranha
9
+ module Parsers
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
+
26
+ LOG_DIR_ENVVAR = 'ARANHA_PARSERS_LOG_DIR'
27
+
28
+ attr_reader :source_address
29
+
30
+ def initialize(url)
31
+ @source_address = ::Aranha::Parsers::SourceAddress.new(url)
32
+ log_content(source_address.serialize, '-source-address')
33
+ end
34
+
35
+ delegate :url, to: :source_address
36
+
37
+ def content
38
+ @content ||= begin
39
+ s = source_address.content
40
+ log_content(s)
41
+ s
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def log_content(content, suffix = '')
48
+ path = log_file(suffix)
49
+
50
+ return unless path
51
+
52
+ File.open(path, 'wb') { |file| file.write(content) }
53
+ end
54
+
55
+ def log_file(suffix)
56
+ dir = log_parsers_dir
57
+ return nil unless dir
58
+
59
+ f = ::File.join(dir, "#{self.class.name.parameterize}#{suffix}.log")
60
+ FileUtils.mkdir_p(File.dirname(f))
61
+ f
62
+ end
63
+
64
+ def log_parsers_dir
65
+ return ENV[LOG_DIR_ENVVAR] if ENV[LOG_DIR_ENVVAR]
66
+ return ::Rails.root.join('log', 'parsers') if rails_root_exist?
67
+
68
+ nil
69
+ end
70
+
71
+ def rails_root_exist?
72
+ ::Rails.root
73
+ true
74
+ rescue NameError
75
+ false
76
+ end
77
+ end
78
+ end
79
+ 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 Html
8
+ ::EacRubyUtils.require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require 'aranha/parsers/base'
5
+ require 'aranha/parsers/html/node/default'
6
+
7
+ module Aranha
8
+ module Parsers
9
+ module Html
10
+ class Base < ::Aranha::Parsers::Base
11
+ class << self
12
+ def fields
13
+ @fields ||= []
14
+ @fields.dup
15
+ end
16
+
17
+ def field(name, type, xpath)
18
+ @fields ||= []
19
+ @fields << Field.new(name, type, xpath)
20
+ end
21
+
22
+ Field = Struct.new(:name, :type, :xpath)
23
+ end
24
+
25
+ def nokogiri
26
+ @nokogiri ||= Nokogiri::HTML(content, &:noblanks)
27
+ end
28
+
29
+ protected
30
+
31
+ def node_parser_class
32
+ ::Aranha::Parsers::Html::Node::Default
33
+ end
34
+
35
+ private
36
+
37
+ def node_parser
38
+ @node_parser ||= node_parser_class.new(fields)
39
+ end
40
+
41
+ def fields
42
+ self.class.fields.map { |f| [f.name, f.type, f.xpath] }
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/html/base'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Html
8
+ class Item < Base
9
+ def data
10
+ @data ||= node_parser.parse(item_node)
11
+ end
12
+
13
+ def item_node
14
+ @item_node ||= begin
15
+ r = item_xpath ? nokogiri.at_xpath(item_xpath) : nokogiri
16
+ raise "Item node not found (Item xpath: #{item_xpath})" unless r
17
+
18
+ r
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/html/base'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Html
8
+ class ItemList < Base
9
+ def data
10
+ items_data
11
+ end
12
+
13
+ def items_data
14
+ count = 0
15
+ @data ||= nokogiri.xpath(items_xpath).map do |m|
16
+ count += 1
17
+ node_parser.parse(m)
18
+ end
19
+ rescue StandardError => e
20
+ raise StandardError, "#{e.message} (Count: #{count})"
21
+ end
22
+
23
+ def items_xpath
24
+ raise "Class #{self.class} has no method \"#{__method__}\". Implement it"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Html
8
+ module Node
9
+ ::EacRubyUtils.require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Parsers
5
+ module Html
6
+ module Node
7
+ class Base
8
+ attr_reader :fields
9
+
10
+ def initialize(fields)
11
+ @fields = fields
12
+ end
13
+
14
+ def parse(node)
15
+ fields.map do |f|
16
+ begin
17
+ [f[0], parse_field(node, f[2], f[1])]
18
+ rescue StandardError => e
19
+ raise StandardError, "#{e.message}\nFields: #{f}"
20
+ end
21
+ end.to_h
22
+ end
23
+
24
+ private
25
+
26
+ def parse_field(node, xpath, parser_method)
27
+ value_method = "#{parser_method}_value"
28
+ return send(value_method, node, xpath) if respond_to?(value_method)
29
+
30
+ raise "Method \"#{value_method}\" not found in #{self.class}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/html/node/base'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Html
8
+ module Node
9
+ class Default < ::Aranha::Parsers::Html::Node::Base
10
+ def string_value(node, xpath)
11
+ if node.at_xpath(xpath)
12
+ sanitize_string(node.at_xpath(xpath).text)
13
+ else
14
+ ''
15
+ end
16
+ end
17
+
18
+ def string_recursive_value(node, xpath, required = true)
19
+ root = node.at_xpath(xpath)
20
+ if root.blank?
21
+ return nil unless required
22
+
23
+ raise "No node found (Xpath: #{xpath})"
24
+ end
25
+ result = string_recursive(root)
26
+ return result if result.present?
27
+ return nil unless required
28
+
29
+ raise "String blank (Xpath: #{xpath})"
30
+ end
31
+
32
+ def string_recursive_optional_value(node, xpath)
33
+ string_recursive_value(node, xpath, false)
34
+ end
35
+
36
+ def quoted_value(node, xpath)
37
+ s = string_value(node, xpath)
38
+ return '' unless s
39
+
40
+ m = /\"([^\"]+)\"/.match(s)
41
+ return m[1] if m
42
+
43
+ ''
44
+ end
45
+
46
+ def integer_value(node, xpath)
47
+ r = string_value(node, xpath)
48
+ return nil if r.blank?
49
+
50
+ m = /\d+/.match(r)
51
+ raise "Integer not found in \"#{r}\"" unless m
52
+
53
+ m[0].to_i
54
+ end
55
+
56
+ def integer_optional_value(node, xpath)
57
+ r = string_value(node, xpath)
58
+ m = /\d+/.match(r)
59
+ m ? m[0].to_i : nil
60
+ end
61
+
62
+ def float_value(node, xpath)
63
+ parse_float(node, xpath, true)
64
+ end
65
+
66
+ def float_optional_value(node, xpath)
67
+ parse_float(node, xpath, false)
68
+ end
69
+
70
+ def array_value(node, xpath)
71
+ r = node.xpath(xpath).map { |n| n.text.strip }
72
+ r.join('|')
73
+ end
74
+
75
+ def join_value(node, xpath)
76
+ m = ''
77
+ node.xpath(xpath).each do |n|
78
+ m << n.text.strip
79
+ end
80
+ m
81
+ end
82
+
83
+ def duration_value(node, xpath)
84
+ m = /(\d+) m/.match(join_value(node, xpath))
85
+ m ? m[1].to_i : nil
86
+ end
87
+
88
+ def regxep(node, xpath, pattern)
89
+ s = string_value(node, xpath)
90
+ m = pattern.match(s)
91
+ return m if m
92
+
93
+ raise "Pattern \"#{pattern}\" not found in string \"#{s}\""
94
+ end
95
+
96
+ private
97
+
98
+ def parse_float(node, xpath, required)
99
+ s = string_value(node, xpath)
100
+ m = /\d+(?:[\.\,](\d+))?/.match(s)
101
+ if m
102
+ m[0].delete('.').tr(',', '.').to_f
103
+ elsif required
104
+ raise "Float value not found in \"#{s}\""
105
+ end
106
+ end
107
+
108
+ def sanitize_string(obj)
109
+ obj.to_s.tr("\u00A0", ' ').strip
110
+ end
111
+
112
+ def string_recursive(node)
113
+ return sanitize_string(node.text) if node.is_a?(::Nokogiri::XML::Text)
114
+
115
+ s = ''
116
+ node.children.each do |child|
117
+ child_s = string_recursive(child)
118
+ s += ' ' + child_s if child_s.present?
119
+ end
120
+ sanitize_string(s)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end