enhanced_marc 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Changes +1 -0
  2. data/LICENSE +21 -0
  3. data/README +51 -0
  4. data/Rakefile +41 -0
  5. data/VERSION +1 -0
  6. data/enhanced_marc-0.1.gem +0 -0
  7. data/enhanced_marc.gemspec +85 -0
  8. data/lib/enhanced_marc.rb +23 -0
  9. data/lib/enhanced_marc/book_record.rb +37 -0
  10. data/lib/enhanced_marc/book_type.rb +87 -0
  11. data/lib/enhanced_marc/computer_record.rb +37 -0
  12. data/lib/enhanced_marc/computer_type.rb +14 -0
  13. data/lib/enhanced_marc/leader.rb +132 -0
  14. data/lib/enhanced_marc/leftovers.rb +122 -0
  15. data/lib/enhanced_marc/map_record.rb +38 -0
  16. data/lib/enhanced_marc/map_type.rb +99 -0
  17. data/lib/enhanced_marc/mixed_record.rb +37 -0
  18. data/lib/enhanced_marc/mixed_type.rb +4 -0
  19. data/lib/enhanced_marc/reader.rb +105 -0
  20. data/lib/enhanced_marc/record.rb +96 -0
  21. data/lib/enhanced_marc/record_type.rb +310 -0
  22. data/lib/enhanced_marc/score_record.rb +38 -0
  23. data/lib/enhanced_marc/score_type.rb +4 -0
  24. data/lib/enhanced_marc/serial_record.rb +37 -0
  25. data/lib/enhanced_marc/serial_type.rb +87 -0
  26. data/lib/enhanced_marc/sound_record.rb +37 -0
  27. data/lib/enhanced_marc/sound_type.rb +4 -0
  28. data/lib/enhanced_marc/visual_record.rb +37 -0
  29. data/lib/enhanced_marc/visual_type.rb +38 -0
  30. data/lib/enhanced_marc/xmlreader.rb +58 -0
  31. data/pkg/enhanced_marc-0.1.gem +0 -0
  32. data/pkg/enhanced_marc-0.1.tgz +0 -0
  33. data/pkg/enhanced_marc-0.1.zip +0 -0
  34. data/pkg/enhanced_marc-0.1/Changes +1 -0
  35. data/pkg/enhanced_marc-0.1/LICENSE +21 -0
  36. data/pkg/enhanced_marc-0.1/README +51 -0
  37. data/pkg/enhanced_marc-0.1/Rakefile +41 -0
  38. data/pkg/enhanced_marc-0.1/test/ts_enhanced_marc.rb +5 -0
  39. data/test/ts_enhanced_marc.rb +5 -0
  40. metadata +113 -0
@@ -0,0 +1,37 @@
1
+ module MARC
2
+
3
+ # A class that represents an individual MARC record. Every record
4
+ # is made up of a collection of MARC::Field objects.
5
+
6
+ class SoundRecord < Record
7
+
8
+ def initialize
9
+ super
10
+ @leader[6] = 'i' if @leader[6,1] == ' '
11
+ @leader[7] = 'm' if @leader[7,1] == ' '
12
+ @record_type = 'REC'
13
+ @bibliographic_level = @leader.get_blvl
14
+ self.extend SoundType
15
+ self.inspect_fixed_fields
16
+ end
17
+
18
+ def is_valid_type?
19
+ return false unless @leader[6,1].match(/[ij]{1}/)
20
+ return true
21
+ end
22
+ def is_valid_blvl?
23
+ return false unless @leader[7,1].match(/[abcdims]{1}/)
24
+ return true
25
+ end
26
+ def self.new_from_record(record)
27
+ rec = SoundRecord.new
28
+ record.instance_variables.each { | var |
29
+ rec.instance_variable_set(var, record.instance_variable_get(var))
30
+ }
31
+ return Exception.new("Incorrect type declaration in leader") unless rec.is_valid_type?
32
+ return Exception.new("Incorrect bibliographic declaration in leader") unless rec.is_valid_blvl?
33
+ return rec
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ module SoundType
2
+ include RecordType
3
+ public :accompanying_matter, :audience_level, :form, :composition_form, :music_format, :is_conference?
4
+ end
@@ -0,0 +1,37 @@
1
+ module MARC
2
+
3
+ # A class that represents an individual MARC record. Every record
4
+ # is made up of a collection of MARC::Field objects.
5
+
6
+ class VisualRecord < Record
7
+
8
+ def initialize
9
+ super
10
+ @leader[6] = 'g' if @leader[6,1] == ' '
11
+ @leader[7] = 'm' if @leader[7,1] == ' '
12
+ @record_type = 'VIS'
13
+ @bibliographic_level = @leader.get_blvl
14
+ self.extend VisualType
15
+ self.inspect_fixed_fields
16
+ end
17
+
18
+ def is_valid_type?
19
+ return false unless @leader[6,1].match(/[gkro]{1}/)
20
+ return true
21
+ end
22
+ def is_valid_blvl?
23
+ return false unless @leader[7,1].match(/[abcdims]{1}/)
24
+ return true
25
+ end
26
+ def self.new_from_record(record)
27
+ rec = VisualRecord.new
28
+ record.instance_variables.each { | var |
29
+ rec.instance_variable_set(var, record.instance_variable_get(var))
30
+ }
31
+ return Exception.new("Incorrect type declaration in leader") unless rec.is_valid_type?
32
+ return Exception.new("Incorrect bibliographic declaration in leader") unless rec.is_valid_blvl?
33
+ return rec
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ module VisualType
2
+ include RecordType
3
+ public :form, :audience_level, :is_govdoc?
4
+
5
+ def running_time
6
+ if @record_type == 'VIS'
7
+ unless self['008'].value[18,3] == 'nnn'
8
+ return "Unknown" if self['008'].value[18,3] == "---"
9
+ return self['008'].value[18,3].sub(/^0*/, '')
10
+ end
11
+ end
12
+ @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
13
+ next unless fxd_fld.value[0,1].match(/[gkor]{1}/)
14
+ unless fxd_fld.value[1,3] == 'nnn'
15
+ return "Unknown" if fxd_fld.value[1,3] == "---"
16
+ return fxd_fld.value[1,3].sub(/^0*/, '')
17
+ end
18
+ }
19
+ return false
20
+ end
21
+
22
+ def material_type(human_readable=false)
23
+ tmat_map = {'a'=>'Art original', 'b'=>'Kit','c'=>'Art reproduction','d'=>'Diorama',
24
+ 'f'=>'Filmstrip','g'=>'Game','i'=>'Picture','k'=>'Graphic','l'=>'Technical drawing',
25
+ 'm'=>'Motion picture','n'=>'Chart','o'=>'Flash card','p'=>'Microscope slide',
26
+ 'q'=>'Model','r'=>'Realia','s'=>'Slide','t'=>'Transparency','v'=>'Videorecording',
27
+ 'w'=>'Toy','z'=>'Other'}
28
+ human_readable = tmat_map if human_readable
29
+ return self.field_parser({:match=>'VIS', :start=>33,:end=>1}, {:match=>/[gkor]{1}/, :start=>16,:end=>1}, human_readable)
30
+ end
31
+
32
+ def technique(human_readable=false)
33
+ tech_map = {'a'=>'Animation','c'=>'Animation and live action','l'=>'Live action',
34
+ 'n'=>'N/A','u'=>'Unknown','z'=>'Other'}
35
+ human_readable = tmat_map if human_readable
36
+ return self.field_parser({:match=>'VIS', :start=>34,:end=>1}, {:match=>/[gkor]{1}/, :start=>17,:end=>1}, human_readable)
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ module MARC
2
+ class XMLReader
3
+ # will accept parse events until a record has been built up
4
+ #
5
+ def build_record
6
+ record = MARC::Record.new
7
+ data_field = nil
8
+ control_field = nil
9
+ subfield = nil
10
+ text = ''
11
+ attrs = nil
12
+
13
+ while @parser.has_next?
14
+ event = @parser.pull
15
+
16
+ if event.text?
17
+ text += REXML::Text::unnormalize(event[0])
18
+ next
19
+ end
20
+
21
+ if event.start_element?
22
+ text = ''
23
+ attrs = event[1]
24
+ case strip_ns(event[0])
25
+ when 'controlfield'
26
+ text = ''
27
+ control_field = MARC::ControlField.new(attrs['tag'])
28
+ when 'datafield'
29
+ text = ''
30
+ data_field = MARC::DataField.new(attrs['tag'], attrs['ind1'],
31
+ attrs['ind2'])
32
+ when 'subfield'
33
+ text = ''
34
+ subfield = MARC::Subfield.new(attrs['code'])
35
+ end
36
+ end
37
+
38
+ if event.end_element?
39
+ case strip_ns(event[0])
40
+ when 'leader'
41
+ record.leader = text
42
+ when 'record'
43
+ return record
44
+ when 'controlfield'
45
+ control_field.value = text
46
+ record.append(control_field)
47
+ when 'datafield'
48
+ record.append(data_field)
49
+ when 'subfield'
50
+ subfield.value = text
51
+ data_field.append(subfield)
52
+ end
53
+ end
54
+ end
55
+ record.to_typed_record
56
+ end
57
+ end
58
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ 2009-08-07: Refactored to monkeypatch ruby-marc rather than replace it.
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2007 Ross Singer
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Enhanced MARC is a set of classes, modules and methods that sit on top of ruby-marc (http://rubyforge.org/projects/marc) to help parse the contents of MARC records more easily and conveniently.
2
+ Installation:
3
+ gem sources -a http://gems.github.com
4
+ sudo gem install rsinger-enhanced_marc
5
+
6
+ Usage:
7
+
8
+ require 'enhanced_marc'
9
+
10
+ reader = MARC::Reader.new('marc.dat')
11
+
12
+ records = []
13
+
14
+ reader.each do | record |
15
+ records << record
16
+ end
17
+
18
+ >> records[0].class
19
+ => MARC::BookRecord
20
+
21
+ >> records[0].is_conference?
22
+ => false
23
+
24
+ >> records[0].is_manuscript?
25
+ => false
26
+
27
+ # Send a boolean true if you want human readable forms, rather than MARC codes.
28
+ >> records[0].literary_form(true)
29
+ => "Non-fiction"
30
+
31
+ >> records[0].nature_of_contents(true)
32
+ => ["Bibliography", "Catalog"]
33
+
34
+ >> records[1].class
35
+ => MARC::SoundRecord
36
+
37
+ >> records[1].composition_form(true)
38
+ => "Jazz"
39
+
40
+ >> records[2].class
41
+ => MARC::MapRecord
42
+
43
+ >> records[2].projection(true)
44
+ => ["Cylindrical", "Mercator"]
45
+
46
+ >> records[2].relief(true)
47
+ => ["Color"]
48
+
49
+
50
+
51
+
@@ -0,0 +1,41 @@
1
+ RUBY_ENHANCED_MARC_VERSION = '0.1'
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'rake/rdoctask'
7
+ require 'rake/packagetask'
8
+ require 'rake/gempackagetask'
9
+
10
+ task :default => [:test]
11
+
12
+ Rake::TestTask.new('test') do |t|
13
+ t.libs << 'lib'
14
+ t.pattern = 'test/tc_*.rb'
15
+ t.verbose = true
16
+ t.ruby_opts = ['-r marc', '-r test/unit']
17
+ end
18
+
19
+ Rake::RDocTask.new('doc') do |rd|
20
+ rd.rdoc_files.include("enhanced_marc/**/*.rb")
21
+ rd.main = 'MARC::Record'
22
+ rd.rdoc_dir = 'doc'
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |s|
28
+
29
+ s.add_dependency('marc')
30
+ s.add_dependency('locale')
31
+ s.name = 'enhanced_marc'
32
+ s.author = 'Ross Singer'
33
+ s.email = 'rossfsinger@gmail.com'
34
+ s.homepage = 'http://github.com/rsinger/enhanced-marc/tree'
35
+ s.summary = 'A DSL for MARC data'
36
+ s.description = 'A set of enhancements to ruby-marc to make parsing MARC data easier'
37
+ end
38
+ rescue LoadError
39
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
40
+ end
41
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # local marc library gets tested
4
+ # not already installed one
5
+ $LOAD_PATH.unshift("enhanced_marc")
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # local marc library gets tested
4
+ # not already installed one
5
+ $LOAD_PATH.unshift("enhanced_marc")
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enhanced_marc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Ross Singer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-06 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: marc
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: locale
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A set of enhancements to ruby-marc to make parsing MARC data easier
36
+ email: rossfsinger@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README
44
+ files:
45
+ - Changes
46
+ - LICENSE
47
+ - README
48
+ - Rakefile
49
+ - VERSION
50
+ - enhanced_marc-0.1.gem
51
+ - enhanced_marc.gemspec
52
+ - lib/enhanced_marc.rb
53
+ - lib/enhanced_marc/book_record.rb
54
+ - lib/enhanced_marc/book_type.rb
55
+ - lib/enhanced_marc/computer_record.rb
56
+ - lib/enhanced_marc/computer_type.rb
57
+ - lib/enhanced_marc/leader.rb
58
+ - lib/enhanced_marc/leftovers.rb
59
+ - lib/enhanced_marc/map_record.rb
60
+ - lib/enhanced_marc/map_type.rb
61
+ - lib/enhanced_marc/mixed_record.rb
62
+ - lib/enhanced_marc/mixed_type.rb
63
+ - lib/enhanced_marc/reader.rb
64
+ - lib/enhanced_marc/record.rb
65
+ - lib/enhanced_marc/record_type.rb
66
+ - lib/enhanced_marc/score_record.rb
67
+ - lib/enhanced_marc/score_type.rb
68
+ - lib/enhanced_marc/serial_record.rb
69
+ - lib/enhanced_marc/serial_type.rb
70
+ - lib/enhanced_marc/sound_record.rb
71
+ - lib/enhanced_marc/sound_type.rb
72
+ - lib/enhanced_marc/visual_record.rb
73
+ - lib/enhanced_marc/visual_type.rb
74
+ - lib/enhanced_marc/xmlreader.rb
75
+ - pkg/enhanced_marc-0.1.gem
76
+ - pkg/enhanced_marc-0.1.tgz
77
+ - pkg/enhanced_marc-0.1.zip
78
+ - pkg/enhanced_marc-0.1/Changes
79
+ - pkg/enhanced_marc-0.1/LICENSE
80
+ - pkg/enhanced_marc-0.1/README
81
+ - pkg/enhanced_marc-0.1/Rakefile
82
+ - pkg/enhanced_marc-0.1/test/ts_enhanced_marc.rb
83
+ - test/ts_enhanced_marc.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/rsinger/enhanced-marc/tree
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.5
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: A DSL for MARC data
112
+ test_files:
113
+ - test/ts_enhanced_marc.rb