anvl 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
data/Gemfile CHANGED
@@ -1,13 +1,4 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.1"
12
- gem "rcov", ">= 0"
13
- end
3
+ # Specify your gem's dependencies in test.gemspec
4
+ gemspec
@@ -1,20 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ anvl (0.3.0)
5
+
1
6
  GEM
2
7
  remote: http://rubygems.org/
3
8
  specs:
4
- git (1.2.5)
5
- jeweler (1.5.1)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
+ diff-lcs (1.1.2)
9
10
  rake (0.8.7)
10
11
  rcov (0.9.9)
11
- shoulda (2.11.3)
12
+ rspec (2.6.0)
13
+ rspec-core (~> 2.6.0)
14
+ rspec-expectations (~> 2.6.0)
15
+ rspec-mocks (~> 2.6.0)
16
+ rspec-core (2.6.4)
17
+ rspec-expectations (2.6.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.6.0)
20
+ yard (0.7.1)
12
21
 
13
22
  PLATFORMS
14
23
  ruby
15
24
 
16
25
  DEPENDENCIES
17
- bundler (~> 1.0.0)
18
- jeweler (~> 1.5.1)
26
+ anvl!
27
+ bundler
28
+ rake
19
29
  rcov
20
- shoulda
30
+ rspec
31
+ yard
@@ -1,20 +1,13 @@
1
- Copyright (c) 2010 Chris Beer
1
+ Copyright (c) 2011 Chris Beer
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
10
6
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
7
+ http://www.apache.org/licenses/LICENSE-2.0
13
8
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -1,8 +1,8 @@
1
- = anvl
1
+ # anvl
2
2
 
3
- Ruby implementation of A Name-Value Language (ANVL)
3
+ This is a Ruby implementation of the [A Name-Value Language (ANVL)](https://wiki.ucop.edu/display/Curation/Anvl) microservice. ANVL (A Name-Value Language) is a simple record syntax based on email headers. An ANVL record is a sequence of data elements ending in a blank line. An element consists of a label, a colon, and an optional value, and a long value may be folded (continued) onto the next line by inserting a newline and indenting the next line.
4
4
 
5
- == Contributing to anvl
5
+ ## Contributing to anvl
6
6
 
7
7
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
8
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -12,8 +12,8 @@ Ruby implementation of A Name-Value Language (ANVL)
12
12
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
13
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
14
 
15
- == Copyright
15
+ ## Copyright
16
16
 
17
- Copyright (c) 2010 Chris Beer. See LICENSE.txt for
17
+ Copyright (c) 2011 Chris Beer. See LICENSE.txt for
18
18
  further details.
19
19
 
data/Rakefile CHANGED
@@ -8,45 +8,41 @@ rescue Bundler::BundlerError => e
8
8
  exit e.status_code
9
9
  end
10
10
  require 'rake'
11
+ require 'rspec'
12
+ require 'rspec/core/rake_task'
11
13
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "anvl"
16
- gem.homepage = "http://github.com/cbeer/anvl"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Ruby implementation of A Name-Value Language (ANVL)}
19
- gem.email = "chris@cbeer.info"
20
- gem.authors = ["Chris Beer"]
21
- # Include your dependencies below. Runtime dependencies are required when using your gem,
22
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
24
- # gem.add_development_dependency 'rspec', '> 1.2.3'
14
+ RSpec::Core::RakeTask.new() do |t|
15
+ t.pattern = "./spec/*_spec.rb" # don't need this, it's default.
16
+ t.rcov = true
17
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
25
18
  end
26
- Jeweler::RubygemsDotOrgTasks.new
27
19
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
20
+ desc "Generate code coverage"
21
+ RSpec::Core::RakeTask.new(:rcov) do |t|
22
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
23
+ t.rcov = true
24
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
33
25
  end
34
26
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- end
41
-
42
- task :default => :test
27
+ task :default => :rcov
28
+ task :hudson => [:rcov, :doc]
43
29
 
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
30
+ # Use yard to build docs
31
+ begin
32
+ require 'yard'
33
+ require 'yard/rake/yardoc_task'
34
+ project_root = File.expand_path(File.dirname(__FILE__))
35
+ doc_destination = File.join(project_root, 'doc')
47
36
 
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "anvl #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
37
+ YARD::Rake::YardocTask.new(:doc) do |yt|
38
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
39
+ [ File.join(project_root, 'README.textile') ]
40
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.textile']
41
+ end
42
+ rescue LoadError
43
+ desc "Generate YARD Documentation"
44
+ task :doc do
45
+ abort "Please install the YARD gem to generate rdoc."
46
+ end
52
47
  end
48
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -1,70 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{anvl}
8
- s.version = "0.2.1"
5
+ s.version = "0.3.0"
6
+ s.description = "Ruby ANVL implementation"
7
+ s.summary = "Ruby ANVL implementation"
9
8
 
10
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
10
  s.authors = ["Chris Beer"]
12
- s.date = %q{2010-12-15}
11
+ s.date = %q{2011-06-12}
13
12
  s.email = %q{chris@cbeer.info}
14
13
  s.extra_rdoc_files = [
15
14
  "LICENSE.txt",
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".document",
20
- "Gemfile",
21
- "Gemfile.lock",
22
- "LICENSE.txt",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "anvl.gemspec",
27
- "lib/anvl.rb",
28
- "lib/anvl/document.rb",
29
- "lib/anvl/element.rb",
30
- "lib/anvl/erc.rb",
31
- "test/helper.rb",
32
- "test/test_anvl.rb",
33
- "test/test_element.rb",
34
- "test/test_erc.rb"
35
- ]
36
- s.homepage = %q{http://github.com/cbeer/anvl}
37
- s.licenses = ["MIT"]
38
- s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.3.7}
40
- s.summary = %q{Ruby implementation of A Name-Value Language (ANVL)}
41
- s.test_files = [
42
- "test/helper.rb",
43
- "test/test_anvl.rb",
44
- "test/test_element.rb",
45
- "test/test_erc.rb"
15
+ "README.textile"
46
16
  ]
47
17
 
48
- if s.respond_to? :specification_version then
49
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
- s.specification_version = 3
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
51
22
 
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_development_dependency(%q<shoulda>, [">= 0"])
54
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
56
- s.add_development_dependency(%q<rcov>, [">= 0"])
57
- else
58
- s.add_dependency(%q<shoulda>, [">= 0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
62
- end
63
- else
64
- s.add_dependency(%q<shoulda>, [">= 0"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
67
- s.add_dependency(%q<rcov>, [">= 0"])
68
- end
23
+ # Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
24
+ s.add_development_dependency "rake"
25
+ s.add_development_dependency "bundler"
26
+ s.add_development_dependency "rspec"
27
+ s.add_development_dependency 'rcov'
28
+ s.add_development_dependency 'yard'
69
29
  end
70
30
 
@@ -1,10 +1,12 @@
1
1
  require 'anvl/element'
2
2
  require 'anvl/document'
3
3
  module ANVL
4
+ # Parse an ANVL document into a hash
4
5
  def self.parse *args
5
6
  Document.parse *args
6
7
  end
7
8
 
9
+ # Serialize a Hash to an ANVL string
8
10
  def self.to_anvl *args
9
11
  anvl = Document.parse *args
10
12
  anvl.to_s
@@ -1,21 +1,25 @@
1
1
  module ANVL
2
2
  class Document # < Hash
3
+ # Parse an ANVL formatted string into an ANVL::Document
4
+ # @param String
3
5
  def self.parse str
4
6
  anvl = self.new str
5
7
  anvl
6
8
  end
7
9
 
10
+ # ANVL key/value pairs
8
11
  attr_reader :entries
9
12
 
10
- def initialize obj = nil
13
+ # @param [String, Hash] obj optional ANVL formatted string or hash values
14
+ def initialize anvl_string_or_hash = nil
11
15
  @entries = Array.new
12
16
 
13
- case obj
17
+ case anvl_string_or_Hash
14
18
  when Hash
15
- self.push obj
19
+ self.push anvl_string_or_hash
16
20
 
17
21
  when String
18
- lines = obj.gsub(/\s?\n\s+/, ' ').split("\n")
22
+ lines = anvl_string_or_hash.gsub(/\s?\n\s+/, ' ').split("\n")
19
23
 
20
24
  lines.each_with_index do |str, i|
21
25
  case str
@@ -28,13 +32,14 @@ module ANVL
28
32
  end
29
33
  end
30
34
 
31
- end if obj
35
+ end if anvl_string_or_hash
32
36
 
33
37
  add_entries_methods
34
38
 
35
39
  gc!
36
40
  end
37
41
 
42
+ # @return [String] an ANVL-formatted string
38
43
  def to_s
39
44
  gc!
40
45
  @entries.map do |obj|
@@ -42,6 +47,7 @@ module ANVL
42
47
  end.join "\n"
43
48
  end
44
49
 
50
+ # @return [Hash] an ordinary hash representation of the ANVL document
45
51
  def to_h
46
52
  gc!
47
53
  h = {}
@@ -58,6 +64,11 @@ module ANVL
58
64
  h
59
65
  end
60
66
 
67
+ # Retrieve an ANVL entry
68
+ # @param [String] display_label
69
+ # @param [Hash] args
70
+ # @option args [Boolean] :raw
71
+ # @return [Array, String]
61
72
  def [] display_label, args = {}
62
73
  v = @entries.select { |x| x =~ display_label }
63
74
  v &&= v.map { |x| x.to_s } unless args[:raw]
@@ -66,6 +77,10 @@ module ANVL
66
77
  end
67
78
  alias_method :fetch, :[]
68
79
 
80
+ # Set an ANVL key/value pair
81
+ # @param [String] display_label
82
+ # @param [String] value
83
+ # @param [Boolean] append (if false (the default), it will overwrite any existing tags for the label)
69
84
  def []= display_label, value, append = false
70
85
  label = convert_label display_label
71
86
  value = [value] unless value.is_a? Array
@@ -79,9 +94,10 @@ module ANVL
79
94
  end
80
95
  end
81
96
  end
82
-
83
97
  alias_method :store, :[]=
84
98
 
99
+ # Append an ANVL key/value pair to the document
100
+ # @param [Hash] key => value to append
85
101
  def push hash
86
102
  hash.each do |label, value|
87
103
  self.store label, value, true
@@ -0,0 +1,10 @@
1
+ module ANVL
2
+ unless ANVL.const_defined? :VERSION
3
+ def self.version
4
+ @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
5
+ end
6
+
7
+ VERSION = self.version
8
+ end
9
+ end
10
+
@@ -0,0 +1,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ANVL" do
4
+ describe "parsing tests" do
5
+ it "should parse empty files" do
6
+ anvl = ANVL.parse('')
7
+ anvl.entries.should have(0).items
8
+ end
9
+
10
+ it "should ignore comment lines" do
11
+ anvl = ANVL.parse("#")
12
+ anvl.entries.should have(0).items
13
+ end
14
+
15
+ it "should handle multiple values" do
16
+ anvl = ANVL.parse "entry:
17
+ a: 1
18
+ a: 2"
19
+
20
+ anvl[:a].should == ["1","2"]
21
+ end
22
+
23
+ it "should suport string or key access" do
24
+ str = 'erc:
25
+ who: Lederberg, Joshua
26
+ what: Studies of Human Families for Genetic Linkage
27
+ when: 1974
28
+ where: http://profiles.nlm.nih.gov/BB/AA/TT/tt.pdf
29
+ note: This is an arbitrary note inside a
30
+ small descriptive record.'
31
+ anvl = ANVL::Document.parse str
32
+ anvl['who'].should == anvl[:who]
33
+
34
+
35
+ end
36
+
37
+
38
+ it "should parse a complete document" do
39
+ anvl = ANVL.parse <<-eos
40
+ entry:
41
+ # first draft
42
+ who: Gilbert, W.S. | Sullivan, Arthur
43
+ what: The Yeomen of
44
+ the Guard
45
+ when/created: 1888
46
+ eos
47
+ anvl[:entry].should == ""
48
+ anvl[:who].should == "Gilbert, W.S. | Sullivan, Arthur"
49
+ anvl[:what].should == "The Yeomen of the Guard"
50
+ anvl[:"when/created"].should == "1888"
51
+
52
+ end
53
+ end
54
+
55
+ describe "serializing test" do
56
+ it "should output an empty document" do
57
+ str = ANVL.to_anvl({})
58
+ str.should == ""
59
+ end
60
+
61
+ it "should handle new lines by indenting appropriately" do
62
+ str = ANVL.to_anvl({:with_newline => "abc\n123"})
63
+ str.should == "with_newline: abc\n 123"
64
+ end
65
+
66
+ it "should support label aliases" do
67
+ str = ANVL.to_anvl(:a => {:display_label => 'A', :value => '123'})
68
+ str.should match(/A: 123/)
69
+ end
70
+
71
+ it "should serialize a complete document" do
72
+ str = ANVL.to_anvl({:entry => [""], :who => ['Gilbert, W.S. | Sullivan, Arthur'], :what => ["The Yeomen of the Guard"], :"when/created" => [1888]})
73
+
74
+ arr = str.split("\n")
75
+
76
+ arr.should include("who: Gilbert, W.S. | Sullivan, Arthur", "what: The Yeomen of the Guard", "when/created: 1888")
77
+
78
+ end
79
+
80
+ it "should support iteratively building a document" do
81
+ anvl = ANVL::Document.new
82
+ anvl[:a].should == []
83
+
84
+ anvl[:a] = 'a'
85
+ anvl.to_h.should == {:a => 'a'}
86
+
87
+ anvl[:a] = ['a', 'b']
88
+ anvl.to_h.should == {:a => ['a', 'b']}
89
+
90
+ anvl.store :a, 'c', true
91
+ anvl.to_h.should == {:a => ['a', 'b', 'c']}
92
+
93
+ anvl << { :a => 'd' }
94
+ anvl.to_h.should == {:a => ['a', 'b', 'c', 'd']}
95
+
96
+ anvl[:b]
97
+ anvl.to_h[:b].should be_nil
98
+
99
+ anvl << { :c => 1 }
100
+ anvl[:c].should == "1"
101
+
102
+ anvl << { :c => 2 }
103
+ anvl[:c].should == ["1", "2"]
104
+
105
+ arr = anvl.to_s.split("\n")
106
+ arr.should include("a: a", "a: b", "a: c", "a: d", "c: 1", "c: 2")
107
+ end
108
+ end
109
+ end
110
+
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'anvl/erc'
3
+
4
+ describe "ERC element" do
5
+ it "should handle basic mapping" do
6
+ h = ANVL::Erc::Element.new :label => 'abc', :value => '123'
7
+ h.to_s.should == "123"
8
+ h.to_anvl.should == "abc: 123"
9
+ end
10
+
11
+ it "should support an initial comment to record natural word order" do
12
+ h = ANVL::Erc::Element.new :label => 'abc', :value => ', van Gogh, Vincent'
13
+ h.to_s.should == "Vincent van Gogh"
14
+ h.to_anvl.should == "abc:, van Gogh, Vincent"
15
+
16
+ h = ANVL::Erc::Element.new :label => 'abc', :value => ', Howell, III, PhD, 1922-1987, Thurston'
17
+ h.to_s.should == "Thurston Howell, III, PhD, 1922-1987"
18
+ h.to_anvl.should == "abc:, Howell, III, PhD, 1922-1987, Thurston"
19
+
20
+ h = ANVL::Erc::Element.new :label => 'abc', :value => ', McCartney, Paul, Sir,'
21
+ h.to_s.should == "Sir Paul McCartney"
22
+ h.to_anvl.should == "abc:, McCartney, Paul, Sir,"
23
+ end
24
+ end
@@ -0,0 +1,136 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'anvl/erc'
3
+
4
+ describe "test ERC record handling" do
5
+ it "should handle empty files" do
6
+ ANVL::Erc.parse('').entries.should have(0).items
7
+ end
8
+
9
+ it "should handle basic ERC record" do
10
+ str = 'erc:
11
+ who: Gibbon, Edward
12
+ what: The Decline and Fall of the Roman Empire
13
+ when: 1781
14
+ where: http://www.ccel.org/g/gibbon/decline/'
15
+
16
+ erc = ANVL::Erc.parse str
17
+
18
+ erc[:erc].should == ""
19
+ erc[:who].should == "Gibbon, Edward"
20
+ erc[:what].should == "The Decline and Fall of the Roman Empire"
21
+ erc[:when].should == "1781"
22
+ erc[:where].should == "http://www.ccel.org/g/gibbon/decline/"
23
+ end
24
+
25
+ it "should support label structure agnostic key access" do
26
+ str = 'erc:'
27
+ erc = ANVL::Erc.parse str
28
+
29
+ erc['marc_856'] = 'abc'
30
+ erc['MARC 856'].should == 'abc'
31
+
32
+ erc['MARC 856'] = '123'
33
+ erc['marc_856'].should == '123'
34
+
35
+ end
36
+
37
+ it "should support internationalized key access" do
38
+ str = 'erc:
39
+ who: Lederberg, Joshua
40
+ h2: Studies of Human Families for Genetic Linkage'
41
+ erc = ANVL::Erc.parse str
42
+
43
+ erc[:who].should == erc['who']
44
+ erc[:who].should == erc[:h1]
45
+ erc[:who].should == erc['wer(h1)']
46
+
47
+ erc[:h2].should == erc[:what]
48
+ erc[:h2].should == erc['was(h2)']
49
+
50
+ end
51
+
52
+ it "should handle multiple values delimited by a semi-colon" do
53
+ str = 'erc:
54
+ who: Smith, J; Wong, D; Khan, H'
55
+ erc = ANVL::Erc.parse str
56
+
57
+ erc[:who].should include("Smith, J", "Wong, D", "Khan, H")
58
+ end
59
+
60
+ it "should handle value normaliation" do
61
+ str = 'erc:
62
+ who:, van Gogh, Vincent
63
+ who:, Howell, III, PhD, 1922-1987, Thurston
64
+ who:, Acme Rocket Factory, Inc., The
65
+ who:, Mao Tse Tung
66
+ who:, McCartney, Pat, Ms,
67
+ who:, McCartney, Paul, Sir,
68
+ who:, McCartney, Petra, Dr,
69
+ what:, Health and Human Services, United States Government
70
+ Department of, The,'
71
+
72
+ erc = ANVL::Erc.parse str
73
+
74
+ erc[:who].should include("Vincent van Gogh", "Thurston Howell, III, PhD, 1922-1987", "The Acme Rocket Factory, Inc.", "Mao Tse Tung", "Ms Pat McCartney", "Sir Paul McCartney", "Dr Petra McCartney")
75
+ erc[:what].should == "The United States Government Department of Health and Human Services"
76
+
77
+ end
78
+
79
+ it "should unescape value encoding" do
80
+ str = 'erc:
81
+ who: %sp%ex%dq'
82
+ h = ANVL::Erc.parse str
83
+ h[:who].should == ' !"'
84
+ end
85
+
86
+ it "should test for completeness" do
87
+ str = 'erc:
88
+ what: The Digital Dilemma
89
+ where: http://books.nap.edu/html/digital%5Fdilemma
90
+ '
91
+
92
+ erc = ANVL::Erc.parse str
93
+ erc.should_not be_complete
94
+
95
+ erc[:who] = '---'
96
+ erc[:when] = '---'
97
+ erc.should be_complete
98
+
99
+ end
100
+
101
+ describe "abbreviated view" do
102
+ it "should parse to full document" do
103
+ str = 'erc: Gibbon, Edward | The Decline and Fall of the Roman Empire
104
+ | 1781 | http://www.ccel.org/g/gibbon/decline/'
105
+ erc = ANVL::Erc.parse str
106
+
107
+ erc[:erc].should be_empty
108
+ erc[:who].should == "Gibbon, Edward"
109
+ erc[:what].should == "The Decline and Fall of the Roman Empire"
110
+ erc[:when].should == "1781"
111
+ erc[:where].should == "http://www.ccel.org/g/gibbon/decline/"
112
+
113
+ end
114
+
115
+ end
116
+
117
+ describe "meta erc document" do
118
+ it "may be considered complete" do
119
+ str = 'meta-erc: NLM | pm9546494 | 19980418
120
+ | http://ark.nlm.nih.gov/12025/pm9546494??'
121
+ erc = ANVL::Erc.parse str
122
+ erc.should be_complete
123
+
124
+ end
125
+ end
126
+
127
+ describe "about erc document" do
128
+ it "should handle missing values" do
129
+ str = 'about-erc: | Bispectrum ; Nonlinearity ; Epilepsy
130
+ ; Cooperativity ; Subdural ; Hippocampus'
131
+ erc = ANVL::Erc.parse str
132
+ erc['about-what'].should include("Bispectrum", "Nonlinearity", "Epilepsy", "Cooperativity", "Subdural", "Hippocampus")
133
+
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'anvl'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anvl
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Chris Beer
@@ -14,66 +15,80 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-15 00:00:00 -05:00
18
+ date: 2011-06-12 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: shoulda
22
+ name: rake
23
+ prerelease: false
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
23
25
  none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
30
33
  type: :development
31
- prerelease: false
32
34
  version_requirements: *id001
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: bundler
37
+ prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
36
39
  none: false
37
40
  requirements:
38
- - - ~>
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
43
+ hash: 3
40
44
  segments:
41
- - 1
42
- - 0
43
45
  - 0
44
- version: 1.0.0
46
+ version: "0"
45
47
  type: :development
46
- prerelease: false
47
48
  version_requirements: *id002
48
49
  - !ruby/object:Gem::Dependency
49
- name: jeweler
50
+ name: rspec
51
+ prerelease: false
50
52
  requirement: &id003 !ruby/object:Gem::Requirement
51
53
  none: false
52
54
  requirements:
53
- - - ~>
55
+ - - ">="
54
56
  - !ruby/object:Gem::Version
57
+ hash: 3
55
58
  segments:
56
- - 1
57
- - 5
58
- - 1
59
- version: 1.5.1
59
+ - 0
60
+ version: "0"
60
61
  type: :development
61
- prerelease: false
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rcov
65
+ prerelease: false
65
66
  requirement: &id004 !ruby/object:Gem::Requirement
66
67
  none: false
67
68
  requirements:
68
69
  - - ">="
69
70
  - !ruby/object:Gem::Version
71
+ hash: 3
70
72
  segments:
71
73
  - 0
72
74
  version: "0"
73
75
  type: :development
74
- prerelease: false
75
76
  version_requirements: *id004
76
- description:
77
+ - !ruby/object:Gem::Dependency
78
+ name: yard
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id005
91
+ description: Ruby ANVL implementation
77
92
  email: chris@cbeer.info
78
93
  executables: []
79
94
 
@@ -81,13 +96,14 @@ extensions: []
81
96
 
82
97
  extra_rdoc_files:
83
98
  - LICENSE.txt
84
- - README.rdoc
99
+ - README.textile
85
100
  files:
86
101
  - .document
102
+ - .gitignore
87
103
  - Gemfile
88
104
  - Gemfile.lock
89
105
  - LICENSE.txt
90
- - README.rdoc
106
+ - README.textile
91
107
  - Rakefile
92
108
  - VERSION
93
109
  - anvl.gemspec
@@ -95,14 +111,15 @@ files:
95
111
  - lib/anvl/document.rb
96
112
  - lib/anvl/element.rb
97
113
  - lib/anvl/erc.rb
98
- - test/helper.rb
99
- - test/test_anvl.rb
100
- - test/test_element.rb
101
- - test/test_erc.rb
114
+ - lib/anvl/version.rb
115
+ - spec/anvl_spec.rb
116
+ - spec/element_spec.rb
117
+ - spec/erc_spec.rb
118
+ - spec/spec_helper.rb
102
119
  has_rdoc: true
103
- homepage: http://github.com/cbeer/anvl
104
- licenses:
105
- - MIT
120
+ homepage:
121
+ licenses: []
122
+
106
123
  post_install_message:
107
124
  rdoc_options: []
108
125
 
@@ -113,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
130
  requirements:
114
131
  - - ">="
115
132
  - !ruby/object:Gem::Version
116
- hash: -2561876318649041604
133
+ hash: 3
117
134
  segments:
118
135
  - 0
119
136
  version: "0"
@@ -122,18 +139,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
139
  requirements:
123
140
  - - ">="
124
141
  - !ruby/object:Gem::Version
142
+ hash: 3
125
143
  segments:
126
144
  - 0
127
145
  version: "0"
128
146
  requirements: []
129
147
 
130
148
  rubyforge_project:
131
- rubygems_version: 1.3.7
149
+ rubygems_version: 1.5.3
132
150
  signing_key:
133
151
  specification_version: 3
134
- summary: Ruby implementation of A Name-Value Language (ANVL)
152
+ summary: Ruby ANVL implementation
135
153
  test_files:
136
- - test/helper.rb
137
- - test/test_anvl.rb
138
- - test/test_element.rb
139
- - test/test_erc.rb
154
+ - spec/anvl_spec.rb
155
+ - spec/element_spec.rb
156
+ - spec/erc_spec.rb
157
+ - spec/spec_helper.rb
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'anvl'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,109 +0,0 @@
1
- require 'helper'
2
-
3
- class TestAnvl < Test::Unit::TestCase
4
- def test_parse_empty
5
- h = ANVL.parse ''
6
- assert_equal(0, h.entries.length)
7
- end
8
-
9
- def test_parse_comment
10
- h = ANVL.parse '#'
11
- assert_equal(0, h.entries.length)
12
- end
13
-
14
- def test_first_draft
15
- h = ANVL.parse 'entry:
16
- # first draft
17
- who: Gilbert, W.S. | Sullivan, Arthur
18
- what: The Yeomen of
19
- the Guard
20
- when/created: 1888'
21
- assert_equal("", h[:entry])
22
- assert_equal('Gilbert, W.S. | Sullivan, Arthur', h[:who])
23
- assert_equal("The Yeomen of the Guard", h[:what])
24
- assert_equal("1888", h[:"when/created"])
25
- end
26
-
27
- def test_multiple_values
28
- h = ANVL::Document.parse 'entry:
29
- a: 1
30
- a: 2'
31
- assert_equal({:a => ["1","2"], :entry => ""}, h.to_h)
32
- end
33
-
34
- def test_key_access
35
- h = ANVL::Document.new
36
- assert_equal([], h[:a])
37
- h[:a] = 'a'
38
- assert_equal({:a => 'a' }, h.to_h)
39
- h[:a] = ['a', 'b']
40
- assert_equal({:a => ['a', 'b'] }, h.to_h)
41
- h[:a].inspect
42
- h.store :a, 'c', true
43
- assert_equal({:a => ['a', 'b', 'c'] }, h.to_h)
44
- assert_equal(['a', 'b', 'c'], h[:a])
45
-
46
- h[:b]
47
- assert_equal({:a => ['a', 'b', 'c'] }, h.to_h)
48
-
49
- h << { :a => 'd' }
50
- assert_equal({:a => ['a', 'b', 'c', 'd'] }, h.to_h)
51
-
52
- h << { :c => 1 }
53
- assert_equal("1", h[:c])
54
-
55
- h << { :c => 2 }
56
- assert_equal(["1", "2"], h[:c])
57
-
58
- str = h.to_s
59
- assert_match(/^a: a$/, str)
60
- assert_match(/^a: b$/, str)
61
- assert_match(/^a: c$/, str)
62
- assert_match(/^a: d$/, str)
63
- assert_match(/^c: 1$/, str)
64
- assert_match(/^c: 2$/, str)
65
- end
66
-
67
- def test_newlines
68
- h = ANVL::Document.new
69
- h[:nl] = "abc\n123"
70
- assert_equal("nl: abc\n 123", h.to_s)
71
- end
72
-
73
- def test_fmt_empty
74
- str = ANVL.to_anvl({})
75
- assert_equal('', str)
76
- end
77
-
78
- def test_fmt_first_draft
79
- str = ANVL.to_anvl({:entry => [""], :who => ['Gilbert, W.S. | Sullivan, Arthur'], :what => ["The Yeomen of the Guard"], :"when/created" => [1888]})
80
- h = ANVL.parse({:entry => [""], :who => ['Gilbert, W.S. | Sullivan, Arthur'], :what => ["The Yeomen of the Guard"], :"when/created" => [1888]})
81
- assert_match(/entry:/, str)
82
- assert_match(/who: Gilbert, W.S. | Sullivan, Arthur/, str)
83
- assert_match(/what: The Yeomen of the Guard/, str)
84
- assert_match(/when\/created: 1888/, str)
85
- end
86
-
87
- def test_display_label
88
- h = ANVL::Document.new
89
- h['a'] = {:display_label => 'A', :value => '123' }
90
- assert_equal("123", h['a'])
91
-
92
- assert_match(/A:/, h.to_s)
93
- end
94
-
95
- def test_str_vs_sym
96
- str = 'erc:
97
- who: Lederberg, Joshua
98
- what: Studies of Human Families for Genetic Linkage
99
- when: 1974
100
- where: http://profiles.nlm.nih.gov/BB/AA/TT/tt.pdf
101
- note: This is an arbitrary note inside a
102
- small descriptive record.'
103
- h = ANVL::Document.parse str
104
-
105
- assert_equal("Lederberg, Joshua", h['who'])
106
- assert_equal("Lederberg, Joshua", h[:who])
107
- end
108
-
109
- end
@@ -1,23 +0,0 @@
1
- require 'helper'
2
-
3
- class TestErcElement < Test::Unit::TestCase
4
- def test_basic
5
- h = ANVL::Erc::Element.new :label => 'abc', :value => '123'
6
- assert_equal('123', h.to_s)
7
- assert_equal('abc: 123', h.to_anvl)
8
- end
9
-
10
- def test_initial_comma_to_recover_natural_word_order
11
- h = ANVL::Erc::Element.new :label => 'abc', :value => ', van Gogh, Vincent'
12
- assert_equal('Vincent van Gogh', h.to_s)
13
- assert_equal('abc:, van Gogh, Vincent', h.to_anvl)
14
-
15
- h = ANVL::Erc::Element.new :label => 'abc', :value => ', Howell, III, PhD, 1922-1987, Thurston'
16
- assert_equal('Thurston Howell, III, PhD, 1922-1987', h.to_s)
17
- assert_equal('abc:, Howell, III, PhD, 1922-1987, Thurston', h.to_anvl)
18
-
19
- h = ANVL::Erc::Element.new :label => 'abc', :value => ', McCartney, Paul, Sir,'
20
- assert_equal('Sir Paul McCartney', h.to_s)
21
- assert_equal('abc:, McCartney, Paul, Sir,', h.to_anvl)
22
- end
23
- end
@@ -1,134 +0,0 @@
1
- require 'helper'
2
- require 'anvl/erc'
3
-
4
- class TestErc < Test::Unit::TestCase
5
- def test_parse_empty
6
- h = ANVL::Erc.parse ''
7
- assert_equal(0, h.entries.length)
8
- end
9
-
10
- def test_basic
11
- str = 'erc:
12
- who: Gibbon, Edward
13
- what: The Decline and Fall of the Roman Empire
14
- when: 1781
15
- where: http://www.ccel.org/g/gibbon/decline/'
16
-
17
- h = ANVL::Erc.parse str
18
- assert_equal("", h[:erc])
19
- assert_equal("Gibbon, Edward", h[:who])
20
- assert_equal("The Decline and Fall of the Roman Empire", h[:what])
21
- assert_equal("1781", h[:when])
22
- assert_equal("http://www.ccel.org/g/gibbon/decline/", h[:where])
23
- end
24
-
25
- def test_complete
26
- str = 'erc:
27
- what: The Digital Dilemma
28
- where: http://books.nap.edu/html/digital%5Fdilemma
29
- '
30
-
31
- h = ANVL::Erc.parse str
32
- assert_equal(false, h.complete?)
33
-
34
- h[:who] = '---'
35
- h[:when] = '---'
36
- assert(h.complete?)
37
- end
38
-
39
- def test_complete_meta
40
- str = 'meta-erc: NLM | pm9546494 | 19980418
41
- | http://ark.nlm.nih.gov/12025/pm9546494??'
42
- h = ANVL::Erc.parse str
43
- assert(h.complete?)
44
- end
45
-
46
- def test_missing_about
47
- str = 'about-erc: | Bispectrum ; Nonlinearity ; Epilepsy
48
- ; Cooperativity ; Subdural ; Hippocampus'
49
- h = ANVL::Erc.parse str
50
- assert_contains(h['about-what'], 'Bispectrum')
51
- assert_contains(h['about-what'], 'Nonlinearity')
52
- assert_contains(h['about-what'], 'Epilepsy')
53
- assert_contains(h['about-what'], 'Cooperativity')
54
- assert_contains(h['about-what'], 'Subdural')
55
- assert_contains(h['about-what'], 'Hippocampus')
56
- end
57
-
58
- def test_abbr
59
- str = 'erc: Gibbon, Edward | The Decline and Fall of the Roman Empire
60
- | 1781 | http://www.ccel.org/g/gibbon/decline/'
61
-
62
- h = ANVL::Erc.parse str
63
- assert_equal("Gibbon, Edward", h[:who])
64
- assert_equal("The Decline and Fall of the Roman Empire", h[:what])
65
- assert_equal("1781", h[:when])
66
- assert_equal("http://www.ccel.org/g/gibbon/decline/", h[:where])
67
- end
68
-
69
- def test_multiple_values
70
- str = 'erc:
71
- who: Smith, J; Wong, D; Khan, H'
72
- h = ANVL::Erc.parse str
73
-
74
- assert_contains(h[:who], 'Smith, J')
75
- assert_contains(h[:who], 'Wong, D')
76
- assert_contains(h[:who], 'Khan, H')
77
- end
78
-
79
- def test_intl
80
- str = 'erc:
81
- who: Lederberg, Joshua
82
- h2: Studies of Human Families for Genetic Linkage'
83
- h = ANVL::Erc.parse str
84
- assert_equal("Lederberg, Joshua", h[:who])
85
- assert_equal("Lederberg, Joshua", h['who'])
86
- assert_equal("Lederberg, Joshua", h[:h1])
87
- assert_equal("Lederberg, Joshua", h['wer(h1)'])
88
- assert_equal("Studies of Human Families for Genetic Linkage", h[:h2])
89
- assert_equal("Studies of Human Families for Genetic Linkage", h[:what])
90
- assert_equal("Studies of Human Families for Genetic Linkage", h['was(h2)'])
91
- end
92
-
93
- def test_label_structure
94
- str = 'erc:'
95
- h = ANVL::Erc.parse str
96
-
97
- h['marc_856'] = 'abc'
98
-
99
- assert_equal("abc", h['marc_856'])
100
- h['MARC 856'] = '123'
101
-
102
- assert_equal("123", h['marc_856'])
103
- end
104
-
105
- def test_initial_comma
106
- str = 'erc:
107
- who:, van Gogh, Vincent
108
- who:, Howell, III, PhD, 1922-1987, Thurston
109
- who:, Acme Rocket Factory, Inc., The
110
- who:, Mao Tse Tung
111
- who:, McCartney, Pat, Ms,
112
- who:, McCartney, Paul, Sir,
113
- who:, McCartney, Petra, Dr,
114
- what:, Health and Human Services, United States Government
115
- Department of, The,'
116
-
117
- h = ANVL::Erc.parse str
118
- assert_contains(h[:who], "Vincent van Gogh")
119
- assert_contains(h[:who], "Thurston Howell, III, PhD, 1922-1987")
120
- assert_contains(h[:who], "The Acme Rocket Factory, Inc.")
121
- assert_contains(h[:who], "Mao Tse Tung")
122
- assert_contains(h[:who], "Ms Pat McCartney")
123
- assert_contains(h[:who], "Sir Paul McCartney")
124
- assert_contains(h[:who], "Dr Petra McCartney")
125
- assert_equal(h[:what], "The United States Government Department of Health and Human Services")
126
- end
127
-
128
- def test_value_encoding
129
- str = 'erc:
130
- who: %sp%ex%dq'
131
- h = ANVL::Erc.parse str
132
- assert_contains(" !\"", h[:who])
133
- end
134
- end