weak_xml 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: 9de2ed9ec121336d705ad7207756be1940c05bff
4
- data.tar.gz: e29c2675bd840107c0517acacc0dd5cb67c0f40e
3
+ metadata.gz: 28f1fcd1035b0186e9ebbfd78ad831a1d1598f29
4
+ data.tar.gz: ddb2a863e7dacf566f175300f440c036289c84c1
5
5
  SHA512:
6
- metadata.gz: 4b304cc23f025b3e8d74d87d87b66950f945cfd73e6dfe9c9bb29f5a784d68eb9e278d3d0fcb93915da84feec2054149ad5ba4a1a0db5a0fe07797f4e62006fa
7
- data.tar.gz: 2657121dd8b75d5ea9a2e3d402aef5ef6adf5b333bdd0046217e59229059e2cf439bdd27f250274f1fe7bb4b53ad46a1ecd38898cbbbb48e852834719407af57
6
+ metadata.gz: c39a32813a211c8b67ac6766841587066c7279c58f1d4614bbf2b5947d53927cc45c67c7ff0427b49cee1e6d58fbba47ebf63cd643e9ac183eff0a23cbe392e9
7
+ data.tar.gz: 964bd144d6f0e55c0a9fb1b98ede708ade79e9d48c5bb3486c246e535f7ea8ea4a642799c2828dc1456ec69707dd855e91ac07f0f084dd3b978df2afd8c4c00e
data/README.md CHANGED
@@ -10,6 +10,8 @@
10
10
  ## Usage
11
11
 
12
12
  ```ruby
13
+ require "weak_xml"
14
+
13
15
  xml = <<-EOXML
14
16
  <xml>
15
17
  <foo>
@@ -24,7 +26,7 @@ xml = <<-EOXML
24
26
  EOXML
25
27
 
26
28
  # .find gets the first node with the given tag or nil
27
- some_node = WeakXml.find("bar", xml) # => #<Fragment ...
29
+ some_node = WeakXml.find("bar", xml) # => #<WeakXml::Fragment ...
28
30
  WeakXml.find("nope", xml) # => nil
29
31
 
30
32
  # you can get the content
@@ -42,7 +44,7 @@ WeakXml.find_all("nope", xml) # => []
42
44
  some_nodes.map(&:content) # => ["content1", "content2", "content3"]
43
45
 
44
46
  # xml/options can be stored within an instance of WeakXml
45
- doc = WeakXml.new(xml, disable_multiline: false)
47
+ doc = WeakXml.new(xml, multiline: false)
46
48
  doc.find("bar").content # => "content1"
47
49
  ```
48
50
 
@@ -39,11 +39,11 @@ class Benchmark::WeakXml::WeakXmlVersusOthers
39
39
  end
40
40
 
41
41
  x.report("WeakXml (-ML)") do
42
- WeakXml.find("z303-id", ALEPH_BOR_INFO_XML, disable_multiline: true).content
42
+ WeakXml.find("z303-id", ALEPH_BOR_INFO_XML, multiline: false).content
43
43
  end
44
44
 
45
45
  x.report("WeakXml (+hint, -ML)") do
46
- WeakXml.find("<z303-id>", ALEPH_BOR_INFO_XML, disable_multiline: true).content
46
+ WeakXml.find("<z303-id>", ALEPH_BOR_INFO_XML, multiline: false).content
47
47
  end
48
48
 
49
49
  x.report("Plain regex") do
@@ -81,11 +81,11 @@ class Benchmark::WeakXml::WeakXmlVersusOthers
81
81
  end
82
82
 
83
83
  x.report("WeakXml (-ML)") do
84
- WeakXml.find("z303-id", ALEPH_BOR_INFO_XML, disable_multiline: true).content
84
+ WeakXml.find("z303-id", ALEPH_BOR_INFO_XML, multiline: false).content
85
85
  end
86
86
 
87
87
  x.report("WeakXml (+hint, -ML)") do
88
- WeakXml.find("<z303-id>", ALEPH_BOR_INFO_XML, disable_multiline: true)#.content
88
+ WeakXml.find("<z303-id>", ALEPH_BOR_INFO_XML, multiline: false)#.content
89
89
  end
90
90
 
91
91
  x.compare!
@@ -115,7 +115,7 @@ class Benchmark::WeakXml::WeakXmlVersusOthers
115
115
  end
116
116
 
117
117
  x.report("WeakXml (-ML)") do
118
- WeakXml.find_all("fee", ALMA_FEES_XML, disable_multiline: true).map { |_fee| _fee.attr("link") }
118
+ WeakXml.find_all("fee", ALMA_FEES_XML, multiline: false).map { |_fee| _fee.attr("link") }
119
119
  end
120
120
 
121
121
  x.compare!
@@ -1,4 +1,6 @@
1
- class Fragment
1
+ require_relative "../weak_xml"
2
+
3
+ class WeakXml::Fragment
2
4
  # Compiling regular expressions is expensive, specially if one uses variable
3
5
  # parts. So, in order to achive the best performance, these should be compiled
4
6
  # upfront without any "runtime dependencies".
@@ -1,3 +1,3 @@
1
1
  class WeakXml
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/weak_xml.rb CHANGED
@@ -3,9 +3,6 @@ require "weak_xml/version"
3
3
  class WeakXml
4
4
  require_relative "./weak_xml/fragment"
5
5
 
6
- #
7
- # class methods
8
- #
9
6
  def self.find(tag, xml, options = {})
10
7
  if matched_string = xml[regex_factory(tag, options)]
11
8
  Fragment.new(tag, matched_string)
@@ -13,13 +10,13 @@ class WeakXml
13
10
  end
14
11
 
15
12
  def self.find_all(tag, xml, options = {})
16
- xml.scan(regex_factory(tag, options)).map! do |_match|
17
- Fragment.new(tag, _match)
13
+ xml.scan(regex_factory(tag, options)).map! do |match|
14
+ Fragment.new(tag, match)
18
15
  end
19
16
  end
20
17
 
21
18
  def self.regex_factory(tag, options = {})
22
- enable_multiline = !options[:disable_multiline]
19
+ options[:multiline] = options[:multiline].nil? ? true : !!options[:multiline]
23
20
 
24
21
  regexp_base =
25
22
  if tag.start_with?("<") && tag.end_with?(">")
@@ -28,12 +25,9 @@ class WeakXml
28
25
  "<#{tag}[>\s].*?<\/#{tag}>"
29
26
  end
30
27
 
31
- Regexp.new(regexp_base, (enable_multiline ? Regexp::MULTILINE : 0))
28
+ Regexp.new(regexp_base, (options[:multiline] ? Regexp::MULTILINE : 0))
32
29
  end
33
30
 
34
- #
35
- # instance methods
36
- #
37
31
  def initialize(xml, options = {})
38
32
  @options = options
39
33
  @xml = xml
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weak_xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers