aranha-parsers 0.16.0 → 0.17.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: 7b411d37103346c68691d1ac9e76c9fe6677e872bd295a4e7867ea4165b0f588
4
- data.tar.gz: 5d75fea05464975630f0dd8777bdfd140011a8a641a2086c18e223c3dabd2985
3
+ metadata.gz: c023094e51e5188e1979f5ab406b595a93b58006c656ccf7bb55609d1b828472
4
+ data.tar.gz: 1dab0c5d8cb5b000949c3484db3f30494cd893e1f82f194627ae622ece43a457
5
5
  SHA512:
6
- metadata.gz: 5656a1c5ba1c00908bb183ad1bf3a6ecc2c1bea254492ea33c0733cb58380cc748a9b23d8d677b61e82aa418889d22995580585198f337dd05ba288ca23cda7b
7
- data.tar.gz: d44b6f14e521c2853b660bddcafab29c4f3e64e4f85030840c5414370188ec7fc5bc6254a20de8b532105cf77d9b99b1223b7cc5d37183d76f86bd09f32ba2d5
6
+ metadata.gz: 9a3da7fef40ee10d63806ae268939285b3eb7778ff2d4fe5570ce305ddb7b2ee9d07abc5cd9f31c7e79b484fa807bb57aa2dd04bd5a46f76251cf5f677576ba9
7
+ data.tar.gz: f96f07f064028911ae1723f97e1cb8543fe44f2e2813e35b70048894788a3a47130e464cef662fa60d75ba07d030eade04fba54b48a04fb6df6c20553622ef32
@@ -9,6 +9,34 @@ module Aranha
9
9
  module Node
10
10
  class Default < ::Aranha::Parsers::Html::Node::Base
11
11
  module NumericSupport
12
+ # @param node [Nokogiri::XML::Element]
13
+ # @param xpath [String]
14
+ # @return [Float]
15
+ def decimal_comma_value(node, xpath)
16
+ parse_decimal_comma(node, xpath, true)
17
+ end
18
+
19
+ # @param node [Nokogiri::XML::Element]
20
+ # @param xpath [String]
21
+ # @return [Float, nil]
22
+ def decimal_comma_optional_value(node, xpath)
23
+ parse_decimal_comma(node, xpath, false)
24
+ end
25
+
26
+ # @param node [Nokogiri::XML::Element]
27
+ # @param xpath [String]
28
+ # @return [Float]
29
+ def decimal_dot_value(node, xpath)
30
+ parse_decimal_dot(node, xpath, true)
31
+ end
32
+
33
+ # @param node [Nokogiri::XML::Element]
34
+ # @param xpath [String]
35
+ # @return [Float, nil]
36
+ def decimal_dot_optional_value(node, xpath)
37
+ parse_decimal_dot(node, xpath, false)
38
+ end
39
+
12
40
  def integer_value(node, xpath)
13
41
  r = string_value(node, xpath)
14
42
  return nil if r.blank?
@@ -33,12 +61,20 @@ module Aranha
33
61
  parse_float(node, xpath, false)
34
62
  end
35
63
 
64
+ # @deprecated Use {#decimal_dot_value} instead.
65
+ # @param node [Nokogiri::XML::Element]
66
+ # @param xpath [String]
67
+ # @return [Float]
36
68
  def us_decimal_value(node, xpath)
37
- parse_us_decimal(node, xpath, true)
69
+ decimal_dot_value(node, xpath)
38
70
  end
39
71
 
72
+ # @deprecated Use {#decimal_dot_optional_value} instead.
73
+ # @param node [Nokogiri::XML::Element]
74
+ # @param xpath [String]
75
+ # @return [Float, nil]
40
76
  def us_decimal_optional_value(node, xpath)
41
- parse_us_decimal(node, xpath, false)
77
+ decimal_dot_optional_value(node, xpath)
42
78
  end
43
79
 
44
80
  private
@@ -53,15 +89,38 @@ module Aranha
53
89
  end
54
90
  end
55
91
 
56
- def parse_us_decimal(node, xpath, required)
92
+ # @param node [Nokogiri::XML::Element]
93
+ # @param xpath [String]
94
+ # @param required [Boolean]
95
+ # @param separator [String]
96
+ # @param delimiter [String]
97
+ # @return [Float, nil]
98
+ def parse_decimal(node, xpath, required, separator, delimiter)
57
99
  s = string_value(node, xpath)
58
- m = /\d+(?:[\.\,](\d+))?/.match(s)
100
+ m = /\d+(?:[#{::Regexp.quote(separator + delimiter)}](\d+))?/.match(s)
59
101
  if m
60
- m[0].delete(',').to_f
102
+ m[0].delete(delimiter).to_f
61
103
  elsif required
62
- raise "US decimal value not found in \"#{s}\""
104
+ raise "decimal [Separator=\"#{separator}, Delimiter=\"#{delimiter}\"] value not " \
105
+ "found in \"#{s}\""
63
106
  end
64
107
  end
108
+
109
+ # @param node [Nokogiri::XML::Element]
110
+ # @param xpath [String]
111
+ # @param required [Boolean]
112
+ # @return [Float, nil]
113
+ def parse_decimal_dot(node, xpath, required)
114
+ parse_decimal(node, xpath, required, '.', ',')
115
+ end
116
+
117
+ # @param node [Nokogiri::XML::Element]
118
+ # @param xpath [String]
119
+ # @param required [Boolean]
120
+ # @return [Float, nil]
121
+ def parse_decimal_comma(node, xpath, required)
122
+ parse_decimal(node, xpath, required, ',', '.')
123
+ end
65
124
  end
66
125
  end
67
126
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aranha
4
4
  module Parsers
5
- VERSION = '0.16.0'
5
+ VERSION = '0.17.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.16.0
4
+ version: 0.17.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: 2023-03-12 00:00:00.000000000 Z
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport