nori 2.7.0 → 2.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +1 -1
- data/lib/nori/core_ext/hash.rb +1 -1
- data/lib/nori/core_ext.rb +1 -1
- data/lib/nori/string_utils.rb +18 -0
- data/lib/nori/version.rb +1 -1
- data/spec/nori/api_spec.rb +1 -1
- data/spec/nori/string_utils_spec.rb +33 -0
- metadata +4 -4
- data/lib/nori/core_ext/string.rb +0 -21
- data/spec/nori/core_ext/string_spec.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e562b494afc72df387f136e51af0c5e0445b528b5515eedad7f60b3d49d207a5
|
4
|
+
data.tar.gz: 5eabad83b50392e39973058c70d6307ddaaeea47934c292fbd472ee0f93680f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6366a2ac0d9dd99e4fd7b0f32d95dfb21f76885ab18fc7f3f7767c5e257b61e3817d2bf13f9a113feb2482fdb6f5a912956ef5d17a3f868a9139e9b55683402f
|
7
|
+
data.tar.gz: cf295850b06961ed67644a8c06c61152cecf5c8512f8a74a03115e47fe8f9a567300d9af8d91504013777400882869cb7016c80563015e6423e86718c7b828bd
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 2.7.1 (2024-07-28)
|
2
|
+
|
3
|
+
* Stop monkey-patching String with #snakecase by @mchu in https://github.com/savonrb/nori/pull/102
|
4
|
+
|
1
5
|
# 2.7.0 (2024-02-13)
|
2
6
|
|
3
7
|
* Added support for ruby 3.1, 3.2, 3.3. Dropped support for ruby 2.7 and below.
|
@@ -12,6 +16,20 @@
|
|
12
16
|
# 2.5.0 (2015-03-31)
|
13
17
|
|
14
18
|
* Formally drop support for ruby 1.8.7. Installing Nori from rubygems for that version should no longer attempt to install versions that will not work.
|
19
|
+
* BREAKING CHANGE: Newlines are now preserved when present in the value of inner text nodes. See the example below:
|
20
|
+
|
21
|
+
before:
|
22
|
+
|
23
|
+
```
|
24
|
+
Nori.new.parse("<outer>\n<embedded>\n<one></one>\n<two></two>\n<embedded>\n</outer>")
|
25
|
+
=> {"outer"=>"<embedded><one></one><two></two><embedded>"}
|
26
|
+
```
|
27
|
+
|
28
|
+
after:
|
29
|
+
```
|
30
|
+
Nori.new.parse("<outer>\n<embedded>\n<one></one>\n<two></two>\n<embedded>\n</outer>")
|
31
|
+
=> {"outer"=>"<embedded>\n<one></one>\n<two></two>\n<embedded>\n"}
|
32
|
+
```
|
15
33
|
|
16
34
|
# 2.4.0 (2014-04-19)
|
17
35
|
|
data/README.md
CHANGED
@@ -89,7 +89,7 @@ Nori lets you specify a custom formula to convert XML tags to Hash keys using `c
|
|
89
89
|
Nori.new.parse('<userResponse><accountStatus>active</accountStatus></userResponse>')
|
90
90
|
# => {"userResponse"=>{"accountStatus"=>"active"}}
|
91
91
|
|
92
|
-
parser = Nori.new(:convert_tags_to => lambda { |tag|
|
92
|
+
parser = Nori.new(:convert_tags_to => lambda { |tag| Nori::StringUtils.snakecase(tag).to_sym })
|
93
93
|
parser.parse('<userResponse><accountStatus>active</accountStatus></userResponse>')
|
94
94
|
# => {:user_response=>{:account_status=>"active"}}
|
95
95
|
```
|
data/lib/nori/core_ext/hash.rb
CHANGED
data/lib/nori/core_ext.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "nori/
|
1
|
+
require "nori/string_utils"
|
2
2
|
require "nori/core_ext/hash"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Nori
|
2
|
+
module StringUtils
|
3
|
+
# Converts a string to snake case.
|
4
|
+
#
|
5
|
+
# @param inputstring [String] The string to be converted to snake case.
|
6
|
+
# @return [String] A copy of the input string converted to snake case.
|
7
|
+
def self.snakecase(inputstring)
|
8
|
+
str = inputstring.dup
|
9
|
+
str.gsub!(/::/, '/')
|
10
|
+
str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
11
|
+
str.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
12
|
+
str.tr!(".", "_")
|
13
|
+
str.tr!("-", "_")
|
14
|
+
str.downcase!
|
15
|
+
str
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/nori/version.rb
CHANGED
data/spec/nori/api_spec.rb
CHANGED
@@ -55,7 +55,7 @@ describe Nori do
|
|
55
55
|
it "converts all tags by a given formula" do
|
56
56
|
xml = '<userResponse id="1"><accountStatus>active</accountStatus></userResponse>'
|
57
57
|
|
58
|
-
snakecase_symbols = lambda { |tag|
|
58
|
+
snakecase_symbols = lambda { |tag| Nori::StringUtils.snakecase(tag).to_sym }
|
59
59
|
nori = nori(:convert_tags_to => snakecase_symbols)
|
60
60
|
|
61
61
|
expect(nori.parse(xml)).to eq({ :user_response => { :@id => "1", :account_status => "active" } })
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Nori::StringUtils do
|
4
|
+
|
5
|
+
describe ".snakecase" do
|
6
|
+
it "lowercases one word CamelCase" do
|
7
|
+
expect(Nori::StringUtils.snakecase("Merb")).to eq("merb")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "makes one underscore snakecase two word CamelCase" do
|
11
|
+
expect(Nori::StringUtils.snakecase("MerbCore")).to eq("merb_core")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "handles CamelCase with more than 2 words" do
|
15
|
+
expect(Nori::StringUtils.snakecase("SoYouWantContributeToMerbCore")).to eq("so_you_want_contribute_to_merb_core")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "handles CamelCase with more than 2 capital letter in a row" do
|
19
|
+
expect(Nori::StringUtils.snakecase("CNN")).to eq("cnn")
|
20
|
+
expect(Nori::StringUtils.snakecase("CNNNews")).to eq("cnn_news")
|
21
|
+
expect(Nori::StringUtils.snakecase("HeadlineCNNNews")).to eq("headline_cnn_news")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does NOT change one word lowercase" do
|
25
|
+
expect(Nori::StringUtils.snakecase("merb")).to eq("merb")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "leaves snake_case as is" do
|
29
|
+
expect(Nori::StringUtils.snakecase("merb_core")).to eq("merb_core")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Harrington
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-07-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bigdecimal
|
@@ -89,18 +89,18 @@ files:
|
|
89
89
|
- lib/nori.rb
|
90
90
|
- lib/nori/core_ext.rb
|
91
91
|
- lib/nori/core_ext/hash.rb
|
92
|
-
- lib/nori/core_ext/string.rb
|
93
92
|
- lib/nori/parser/nokogiri.rb
|
94
93
|
- lib/nori/parser/rexml.rb
|
95
94
|
- lib/nori/string_io_file.rb
|
95
|
+
- lib/nori/string_utils.rb
|
96
96
|
- lib/nori/string_with_attributes.rb
|
97
97
|
- lib/nori/version.rb
|
98
98
|
- lib/nori/xml_utility_node.rb
|
99
99
|
- nori.gemspec
|
100
100
|
- spec/nori/api_spec.rb
|
101
101
|
- spec/nori/core_ext/hash_spec.rb
|
102
|
-
- spec/nori/core_ext/string_spec.rb
|
103
102
|
- spec/nori/nori_spec.rb
|
103
|
+
- spec/nori/string_utils_spec.rb
|
104
104
|
- spec/spec_helper.rb
|
105
105
|
homepage: https://github.com/savonrb/nori
|
106
106
|
licenses:
|
data/lib/nori/core_ext/string.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Nori
|
2
|
-
module CoreExt
|
3
|
-
module String
|
4
|
-
|
5
|
-
# Returns the String in snake_case.
|
6
|
-
def snakecase
|
7
|
-
str = dup
|
8
|
-
str.gsub!(/::/, '/')
|
9
|
-
str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
10
|
-
str.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
11
|
-
str.tr! ".", "_"
|
12
|
-
str.tr! "-", "_"
|
13
|
-
str.downcase!
|
14
|
-
str
|
15
|
-
end unless method_defined?(:snakecase)
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
String.send :include, Nori::CoreExt::String
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe String do
|
4
|
-
|
5
|
-
describe "#snakecase" do
|
6
|
-
it "lowercases one word CamelCase" do
|
7
|
-
expect("Merb".snakecase).to eq("merb")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "makes one underscore snakecase two word CamelCase" do
|
11
|
-
expect("MerbCore".snakecase).to eq("merb_core")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "handles CamelCase with more than 2 words" do
|
15
|
-
expect("SoYouWantContributeToMerbCore".snakecase).to eq("so_you_want_contribute_to_merb_core")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "handles CamelCase with more than 2 capital letter in a row" do
|
19
|
-
expect("CNN".snakecase).to eq("cnn")
|
20
|
-
expect("CNNNews".snakecase).to eq("cnn_news")
|
21
|
-
expect("HeadlineCNNNews".snakecase).to eq("headline_cnn_news")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "does NOT change one word lowercase" do
|
25
|
-
expect("merb".snakecase).to eq("merb")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "leaves snake_case as is" do
|
29
|
-
expect("merb_core".snakecase).to eq("merb_core")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|