anvl-converter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d07e26a4986332542f86866a21504c4d81978a99
4
+ data.tar.gz: c257c697c0af18b8df1e95136e121849fad58442
5
+ SHA512:
6
+ metadata.gz: 82ebde4c91d00dc847e9fd0b23ae42a509f8a8ba348a0c266c828faaf50c403c99dfd3a97b6e9c132b95715767edc2a2d239dbcddc385981028d9380b0a5f369
7
+ data.tar.gz: 836613db75915e1c2fb514cdae24fa393636771924058373595a4e64a29cefc11b887df86dbec3dd701b6481b1a815ac4fd119a10720b4d9c4dd45d37e0171c2
@@ -0,0 +1,51 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ .DS_Store
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
4
+ addons:
5
+ code_climate:
6
+ repo_token: "$CODECLIMATE_REPO_TOKEN"
7
+ install:
8
+ - travis_retry bundle install
9
+ script:
10
+ - bundle exec rspec
11
+ - bundle exec codeclimate-test-reporter || true
12
+ notifications:
13
+ email: false
14
+ deploy:
15
+ provider: rubygems
16
+ api_key:
17
+ secure: BMX2JmLCio7KJm3coR6Jz5/ygERi7oAL4xSNhNffQMcHa6cZn06HpNjMWVtU/TFouI3AN+tAVpe9RIoLpCEYCPfXDholi1AoGIDhaxDG+PopnTsGJUchs9xpsyaOZcqdNRl55EBEozm28qVCQDmJbket2vaiguUI/Scf+fNTuslK3azz8r4slpl+4PxiaZRuoCnN0YGI3pdG41jfuoEWY2YJlgShkXiYiUdeKtEjzGUgN/ky6GYxVx53rd0AtBlblYfa3KjTR0/8j4/ej/duWiXW4XRpsEJNL9NZDdFJ2WoLG8M71K8DSn7dHFx9V2cK0J92kGZUCfIZWt4SmtAYvyPu3hw690ORJubNRSNe/uMIx4E10L1YbXQL3VPlcOR0UgYziy2HQiC93MCskNtPbax+MYDFgl0a9COVrskXnRXgDY8/3EoeoOXZGuNRIhH3PLBk32bDzdgOaRFriqX4Y47XHkllis2hh0gO6UHuzIj7TrYJpMcdTDCa3aYAu4P7yRhvMtaCvkLOywcAG/Qm+tv9mfDWWEi2ZtCfGk+G+C8K5pCVX9/mUfY4zSdsztD0qL6IJfv4Lv3YoOAHx2RNDGmsNBr0LsNGwOpe52hkD6UC1YNWzDdlcjmaPr7cv5x0FURpfJBq01SjYbfRP0aq/6tTpinaZO3E5l0byICPuOU=
18
+ gem: anvl-converter
19
+ on:
20
+ tags: true
21
+ repo: datacite/anvl-converter
@@ -0,0 +1,5 @@
1
+ ## v.0.1.0 (January 8, 2017)
2
+
3
+ [anvl-converter 0.1.0](https://github.com/datacite/anvl-converter/releases/tag/v.0.1.0) was released on January 8, 2017:
4
+
5
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ anvl-converter (0.1.0)
5
+ activesupport (>= 4.2.5, < 6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.1.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ codeclimate-test-reporter (1.0.8)
16
+ simplecov (<= 0.13)
17
+ concurrent-ruby (1.0.5)
18
+ diff-lcs (1.3)
19
+ docile (1.1.5)
20
+ i18n (0.9.1)
21
+ concurrent-ruby (~> 1.0)
22
+ json (2.1.0)
23
+ minitest (5.11.1)
24
+ rake (12.3.0)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.1)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.0)
38
+ simplecov (0.13.0)
39
+ docile (~> 1.1.0)
40
+ json (>= 1.8, < 3)
41
+ simplecov-html (~> 0.10.0)
42
+ simplecov-html (0.10.2)
43
+ thread_safe (0.3.6)
44
+ tzinfo (1.2.4)
45
+ thread_safe (~> 0.1)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ anvl-converter!
52
+ bundler (~> 1.0)
53
+ codeclimate-test-reporter (~> 1.0, >= 1.0.8)
54
+ rake (~> 12.0)
55
+ rspec (~> 3.4)
56
+ simplecov
57
+
58
+ BUNDLED WITH
59
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 DataCite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # anvl-converter
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/anvl-converter.svg)](https://badge.fury.io/rb/anvl-converter) [![Build Status](https://travis-ci.org/datacite/anvl-converter.svg?branch=master)](https://travis-ci.org/datacite/anvl-converter) [![Maintainability](https://api.codeclimate.com/v1/badges/24b09e147fe522875d4c/maintainability)](https://codeclimate.com/github/datacite/anvl-converter/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/24b09e147fe522875d4c/test_coverage)](https://codeclimate.com/github/datacite/anvl-converter/test_coverage)
4
+
5
+ A Name-Value Language (ANVL) parser in Ruby
6
+
7
+ ANVL serializing and parsing, based on Python code at https://ezid.cdlib.org/doc/apidoc.html,
8
+ and Ruby code at https://github.com/duke-libraries/ezid-client.
9
+
10
+ More info about ANVL [here](https://tools.ietf.org/html/draft-kunze-anvl-01).
11
+
12
+ ## Development
13
+
14
+ We use rspec for unit testing:
15
+
16
+ ```
17
+ bundle exec rspec
18
+ ```
19
+
20
+ Follow along via [Github Issues](https://github.com/datacite/anvl-converter/issues).
21
+
22
+ ### Note on Patches/Pull Requests
23
+
24
+ * Fork the project
25
+ * Write tests for your new feature or a test that reproduces a bug
26
+ * Implement your feature or make a bug fix
27
+ * Do not mess with Rakefile, version or history
28
+ * Commit, push and make a pull request. Bonus points for topical branches.
29
+
30
+ ## License
31
+ **anvl-converter** is released under the [MIT License](https://github.com/datacite/anvl-converter/blob/master/LICENSE.md).
@@ -0,0 +1,28 @@
1
+ require "date"
2
+ require File.expand_path("../lib/anvl/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.authors = "Martin Fenner"
6
+ s.email = "mfenner@datacite.org"
7
+ s.name = "anvl-converter"
8
+ s.homepage = "https://github.com/datacite/anvl-converter"
9
+ s.summary = "Ruby library to parse and generate ANVL"
10
+ s.date = Date.today
11
+ s.description = "Ruby library to parse and generate ANVL."
12
+ s.require_paths = ["lib"]
13
+ s.version = Anvl::VERSION
14
+ s.extra_rdoc_files = ["README.md"]
15
+ s.license = 'MIT'
16
+
17
+ # Declary dependencies here, rather than in the Gemfile
18
+ s.add_development_dependency 'bundler', '~> 1.0'
19
+ s.add_development_dependency 'rspec', '~> 3.4'
20
+ s.add_development_dependency 'rake', '~> 12.0'
21
+ s.add_dependency 'activesupport', '>= 4.2.5', '< 6'
22
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.8'
23
+ s.add_development_dependency 'simplecov'
24
+
25
+ s.require_paths = ["lib"]
26
+ s.files = `git ls-files`.split($/)
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
2
+
3
+ require 'anvl/core_ext/ruby/hash'
4
+ require 'anvl/core_ext/ruby/string'
5
+ require "anvl/version"
@@ -0,0 +1,6 @@
1
+ class Hash
2
+ def to_anvl
3
+ lines = self.map { |k, v| [k.to_s.kanvlesc, v.to_s.anvlesc].join(": ") }
4
+ lines.join("\n").force_encoding(Encoding::UTF_8)
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ class String
2
+ def from_anvl
3
+ hsh = self.split("\n").reduce({}) do |sum, line|
4
+ if line.start_with?("#")
5
+ # ignore
6
+ elsif line.include?(":")
7
+ k, v = line.split(":", 2)
8
+ sum[k.to_s.strip.kanvlunesc] = v.to_s.strip.anvlunesc
9
+ elsif line.start_with?(" ")
10
+ sum[sum.keys.last] += " " + line.strip
11
+ end
12
+
13
+ sum
14
+ end
15
+
16
+ # use string or symbol for keys
17
+ HashWithIndifferentAccess.new(hsh)
18
+ end
19
+
20
+ def kanvlesc
21
+ self.anvlesc.gsub(/:/, "%3A")
22
+ end
23
+
24
+ def anvlesc
25
+ self.gsub(/%/, "%25").gsub(/\n/, "%0A").gsub(/\r/, "%0D")
26
+ end
27
+
28
+ def kanvlunesc
29
+ self.gsub(/%3A/, ":").anvlunesc
30
+ end
31
+
32
+ def anvlunesc
33
+ self.gsub(/%25/, "%").gsub(/%0A/, "\n").gsub(/%0D/, "\r")
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Anvl
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+ context "to_anvl" do
5
+ it "convert" do
6
+ hsh = { "_status" => "public" }
7
+ expect(hsh.to_anvl).to eq("_status: public")
8
+ end
9
+
10
+ it "escape newlines" do
11
+ hsh = { "name" => "Josiah\nCarberry" }
12
+ expect(hsh.to_anvl).to eq("name: Josiah%0ACarberry")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ require 'anvl'
8
+ require 'rspec'
9
+
10
+ RSpec.configure do |config|
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ context "from_anvl" do
5
+ it "convert" do
6
+ str = "_status: public"
7
+ expect(str.from_anvl).to eq("_status"=>"public")
8
+ end
9
+
10
+ it "escaped newlines" do
11
+ str = "name: Josiah%0ACarberry"
12
+ expect(str.from_anvl).to eq("name"=>"Josiah\nCarberry")
13
+ end
14
+
15
+ it "ignore comment" do
16
+ str = "# first draft"
17
+ expect(str.from_anvl).to eq({})
18
+ end
19
+
20
+ it "draft example" do
21
+ str = <<-DOC
22
+ entry:
23
+ # first draft
24
+ who: Gilbert, W.S. | Sullivan, Arthur
25
+ what: The Yeomen of
26
+ the Guard
27
+ when/created: 1888
28
+ DOC
29
+ anvl = str.from_anvl
30
+ expect(anvl["entry"]).to eq("")
31
+ expect(anvl["who"]).to eq("Gilbert, W.S. | Sullivan, Arthur")
32
+ expect(anvl["what"]).to eq("The Yeomen of the Guard")
33
+ expect(anvl["when/created"]).to eq("1888")
34
+ end
35
+
36
+ it "draft example using symbol keys" do
37
+ str = <<-DOC
38
+ entry:
39
+ # first draft
40
+ who: Gilbert, W.S. | Sullivan, Arthur
41
+ what: The Yeomen of
42
+ the Guard
43
+ when/created: 1888
44
+ DOC
45
+ anvl = str.from_anvl
46
+ expect(anvl[:entry]).to eq("")
47
+ expect(anvl[:who]).to eq("Gilbert, W.S. | Sullivan, Arthur")
48
+ expect(anvl[:what]).to eq("The Yeomen of the Guard")
49
+ expect(anvl[:"when/created"]).to eq("1888")
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anvl-converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Fenner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.5
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '6'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 4.2.5
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '6'
75
+ - !ruby/object:Gem::Dependency
76
+ name: codeclimate-test-reporter
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.0'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.8
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.0'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.0.8
95
+ - !ruby/object:Gem::Dependency
96
+ name: simplecov
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ description: Ruby library to parse and generate ANVL.
110
+ email: mfenner@datacite.org
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files:
114
+ - README.md
115
+ files:
116
+ - ".gitignore"
117
+ - ".travis.yml"
118
+ - CHANGELOG.md
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.md
122
+ - README.md
123
+ - anvl-converter.gemspec
124
+ - lib/anvl.rb
125
+ - lib/anvl/core_ext/ruby/hash.rb
126
+ - lib/anvl/core_ext/ruby/string.rb
127
+ - lib/anvl/version.rb
128
+ - spec/hash_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/string_spec.rb
131
+ homepage: https://github.com/datacite/anvl-converter
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.6.12
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Ruby library to parse and generate ANVL
155
+ test_files:
156
+ - spec/hash_spec.rb
157
+ - spec/spec_helper.rb
158
+ - spec/string_spec.rb