rmarc 0.1.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.
@@ -0,0 +1,42 @@
1
+ # $Id: control_field.rb,v 1.3 2005/12/05 19:36:41 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ require 'rmarc/model/variable_field'
22
+
23
+ module RMARC
24
+
25
+ # Represents a control field in a MARC record.
26
+ class ControlField < VariableField
27
+ attr_reader :data
28
+
29
+ attr_writer :data
30
+
31
+ def initialize(tag, data = nil)
32
+ super(tag)
33
+ @data = data
34
+ end
35
+
36
+ # Returns a string representaiton for a conctrol field.
37
+ def to_s
38
+ super + "#@data"
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,68 @@
1
+ ## $Id: data_field.rb,v 1.3 2005/12/05 19:37:09 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ require 'rmarc/model/variable_field'
22
+
23
+ module RMARC
24
+
25
+ # Represents a data field in a MARC record. The module Enumerable is
26
+ # mixed in to enable searching within subfields using each.
27
+ class DataField < VariableField
28
+ include Enumerable
29
+
30
+ attr_reader :ind1, :ind2, :subfields
31
+
32
+ attr_writer :ind1, :ind2, :subfields
33
+
34
+ def initialize(tag, ind1, ind2)
35
+ super(tag)
36
+ @ind1 = ind1
37
+ @ind2 = ind2
38
+ @subfields = Array.new
39
+ end
40
+
41
+ # Adds a subfield.
42
+ def add(subf)
43
+ @subfields.push(subf)
44
+ end
45
+
46
+ # Removes a subfield
47
+ def remove(subf)
48
+ @subfields.delete(subf)
49
+ end
50
+
51
+ # Implements Enumarable.each to provide an iterator over all
52
+ # subfields.
53
+ def each
54
+ for subfield in @subfields
55
+ yield subfield
56
+ end
57
+ end
58
+
59
+ # Returns a string representation of the data field.
60
+ def to_s
61
+ a = ""
62
+ a << super << @ind1 << @ind2
63
+ subfields.each { |s| a << s.to_s }
64
+ return a
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,36 @@
1
+ # $Id: directory.rb,v 1.3 2005/12/05 19:36:41 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ module RMARC
22
+
23
+ # Represents a directory in a MARC record.
24
+ class Directory
25
+ attr_reader :tag, :length, :start
26
+
27
+ attr_writer :tag, :length, :start
28
+
29
+ def initialize(tag, length, start)
30
+ @tag = tag
31
+ @length = length.to_i
32
+ @start = start.to_i
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,65 @@
1
+ # $Id: leader.rb,v 1.4 2005/12/07 19:50:35 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ module RMARC
22
+
23
+ # Represents a leader or record label in a MARC record.
24
+ class Leader
25
+
26
+ attr_reader :record_length, :record_status, :record_type, :impl_defined1, :char_coding, :indicator_count, :subfield_code_length, :base_address, :impl_defined2, :entry_map
27
+
28
+ attr_writer :record_length, :record_status, :record_type, :impl_defined1, :char_coding, :indicator_count, :subfield_code_length, :base_address, :impl_defined2, :entry_map
29
+
30
+ def initialize(ldr = nil)
31
+ if (ldr == nil)
32
+ @record_length = 0
33
+ @record_status = "n"
34
+ @record_type = "a"
35
+ @impl_defined1 = "m "
36
+ @char_coding = " "
37
+ @indicator_count = "2"
38
+ @subfield_code_length = "2"
39
+ @base_address = 0
40
+ @impl_defined2 = "a "
41
+ @entry_map = "4500"
42
+ else
43
+ @record_length = ldr[0,5].to_i
44
+ @record_status = ldr[5].chr
45
+ @record_type = ldr[6].chr
46
+ @impl_defined1 = ldr[7,2].to_s
47
+ @char_coding = ldr[9].chr
48
+ @indicator_count = ldr[10].chr
49
+ @subfield_code_length = ldr[11].chr
50
+ @base_address = ldr[12,5].to_i
51
+ @impl_defined2 = ldr[17,3].to_s
52
+ @entry_map = ldr[20,4].to_s
53
+ end
54
+ end
55
+
56
+ # Returns a string representation for a MARC record.
57
+ def to_s
58
+ "%05d" % @record_length +
59
+ "#@record_status#@record_type#@impl_defined1#@char_coding" +
60
+ "#@indicator_count#@subfield_code_length" +
61
+ "%05d" % @base_address + "#@impl_defined2#@entry_map"
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,64 @@
1
+ # $Id: record.rb,v 1.3 2005/12/05 19:37:09 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ module RMARC
22
+
23
+ # Represents a MARC record. The module Enumerable is
24
+ # mixed in to enable searching within variable fields
25
+ # using each.
26
+ class Record
27
+ include Enumerable
28
+
29
+ attr_reader :leader, :fields
30
+
31
+ attr_writer :leader, :fields
32
+
33
+ def initialize(leader = nil)
34
+ @leader = leader
35
+ @fields = Array.new
36
+ end
37
+
38
+ # Adds a field.
39
+ def add(fld)
40
+ @fields.push(fld)
41
+ end
42
+
43
+ # Removes a field.
44
+ def remove(fld)
45
+ @fields.delete(fld)
46
+ end
47
+
48
+ # Implements Enumarable.each to provide an iterator over all
49
+ # variable fields.
50
+ def each
51
+ for field in @fields
52
+ yield field
53
+ end
54
+ end
55
+
56
+ # Returns a string representation of the record.
57
+ def to_s
58
+ a = "Leader: #{@leader.to_s}\n"
59
+ @fields.each { |f| a << "#{f.to_s}\n" }
60
+ return a
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,39 @@
1
+ # $Id: subfield.rb,v 1.3 2005/12/05 19:36:41 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ module RMARC
22
+
23
+ # Represents a subfield in a MARC record.
24
+ class Subfield
25
+ attr_reader :code, :data
26
+
27
+ attr_writer :code, :data
28
+
29
+ def initialize(code, data = nil)
30
+ @code = code
31
+ @data = data
32
+ end
33
+
34
+ def to_s
35
+ "$#@code#@data"
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,38 @@
1
+ # $Id: variable_field.rb,v 1.3 2005/12/05 19:36:41 bpeters Exp $
2
+ #
3
+ # Copyright (c) 2005 Bas Peters
4
+ #
5
+ # This file is part of RMARC
6
+ #
7
+ # RMARC is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # RMARC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with RMARC; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ module RMARC
22
+
23
+ # Represents a variable field in a MARC record.
24
+ class VariableField
25
+ attr_reader :tag
26
+
27
+ attr_writer :tag
28
+
29
+ def initialize(tag)
30
+ @tag = tag
31
+ end
32
+
33
+ def to_s
34
+ "#@tag "
35
+ end
36
+ end
37
+
38
+ end
data/test/chabon.mrc ADDED
@@ -0,0 +1 @@
1
+ 00759cam a2200229 a 45000010009000000050017000090080041000260200033000670400018001001000021001182450078001392600038002173000021002556500052002766500035003286500030003636510030003936500024004236500026004476550029004736550027005021193987620041229190604.0000313s2000 nyu 000 1 eng  a0679450041 (acid-free paper) aDLCcDLCdDLC1 aChabon, Michael.14aThe amazing adventures of Kavalier and Clay :ba novel /cMichael Chabon. aNew York :bRandom House,cc2000. a639 p. ;c25 cm. 0aComic books, strips, etc.xAuthorshipvFiction. 0aHeroes in mass mediavFiction. 0aCzech AmericansvFiction. 0aNew York (N.Y.)vFiction. 0aYoung menvFiction. 0aCartoonistsvFiction. 7aHumorous stories.2gsafd 7aBildungsromane.2gsafd00714cam a2200205 a 45000010009000000050017000090080041000260200015000670200022000820400018001041000021001222450034001432500012001772600067001893000021002565200175002776500013004526500023004656500020004881288337620030616111422.0020805s2002 nyu j 000 1 eng  a0786808772 a0786816155 (pbk.) aDLCcDLCdDLC1 aChabon, Michael.10aSummerland /cMichael Chabon. a1st ed. aNew York :bMiramax Books/Hyperion Books for Children,cc2002. a500 p. ;c22 cm. aEthan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy. 1aFantasy. 1aBaseballvFiction. 1aMagicvFiction.
data/test/chabon.xml ADDED
@@ -0,0 +1,116 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><collection xmlns="http://www.loc.gov/MARC21/slim">
2
+ <record>
3
+ <leader>00759cam a2200229 a 4500</leader>
4
+ <controlfield tag="001">11939876</controlfield>
5
+ <controlfield tag="005">20041229190604.0</controlfield>
6
+ <controlfield tag="008">000313s2000 nyu 000 1 eng </controlfield>
7
+ <datafield tag="020" ind1=" " ind2=" ">
8
+ <subfield code="a">0679450041 (acid-free paper)</subfield>
9
+ </datafield>
10
+ <datafield tag="040" ind1=" " ind2=" ">
11
+ <subfield code="a">DLC</subfield>
12
+ <subfield code="c">DLC</subfield>
13
+ <subfield code="d">DLC</subfield>
14
+ </datafield>
15
+ <datafield tag="100" ind1="1" ind2=" ">
16
+ <subfield code="a">Chabon, Michael.</subfield>
17
+ </datafield>
18
+ <datafield tag="245" ind1="1" ind2="4">
19
+ <subfield code="a">The amazing adventures of Kavalier and Clay :</subfield>
20
+ <subfield code="b">a novel /</subfield>
21
+ <subfield code="c">Michael Chabon.</subfield>
22
+ </datafield>
23
+ <datafield tag="260" ind1=" " ind2=" ">
24
+ <subfield code="a">New York :</subfield>
25
+ <subfield code="b">Random House,</subfield>
26
+ <subfield code="c">c2000.</subfield>
27
+ </datafield>
28
+ <datafield tag="300" ind1=" " ind2=" ">
29
+ <subfield code="a">639 p. ;</subfield>
30
+ <subfield code="c">25 cm.</subfield>
31
+ </datafield>
32
+ <datafield tag="650" ind1=" " ind2="0">
33
+ <subfield code="a">Comic books, strips, etc.</subfield>
34
+ <subfield code="x">Authorship</subfield>
35
+ <subfield code="v">Fiction.</subfield>
36
+ </datafield>
37
+ <datafield tag="650" ind1=" " ind2="0">
38
+ <subfield code="a">Heroes in mass media</subfield>
39
+ <subfield code="v">Fiction.</subfield>
40
+ </datafield>
41
+ <datafield tag="650" ind1=" " ind2="0">
42
+ <subfield code="a">Czech Americans</subfield>
43
+ <subfield code="v">Fiction.</subfield>
44
+ </datafield>
45
+ <datafield tag="651" ind1=" " ind2="0">
46
+ <subfield code="a">New York (N.Y.)</subfield>
47
+ <subfield code="v">Fiction.</subfield>
48
+ </datafield>
49
+ <datafield tag="650" ind1=" " ind2="0">
50
+ <subfield code="a">Young men</subfield>
51
+ <subfield code="v">Fiction.</subfield>
52
+ </datafield>
53
+ <datafield tag="650" ind1=" " ind2="0">
54
+ <subfield code="a">Cartoonists</subfield>
55
+ <subfield code="v">Fiction.</subfield>
56
+ </datafield>
57
+ <datafield tag="655" ind1=" " ind2="7">
58
+ <subfield code="a">Humorous stories.</subfield>
59
+ <subfield code="2">gsafd</subfield>
60
+ </datafield>
61
+ <datafield tag="655" ind1=" " ind2="7">
62
+ <subfield code="a">Bildungsromane.</subfield>
63
+ <subfield code="2">gsafd</subfield>
64
+ </datafield>
65
+ </record>
66
+ <record>
67
+ <leader>00714cam a2200205 a 4500</leader>
68
+ <controlfield tag="001">12883376</controlfield>
69
+ <controlfield tag="005">20030616111422.0</controlfield>
70
+ <controlfield tag="008">020805s2002 nyu j 000 1 eng </controlfield>
71
+ <datafield tag="020" ind1=" " ind2=" ">
72
+ <subfield code="a">0786808772</subfield>
73
+ </datafield>
74
+ <datafield tag="020" ind1=" " ind2=" ">
75
+ <subfield code="a">0786816155 (pbk.)</subfield>
76
+ </datafield>
77
+ <datafield tag="040" ind1=" " ind2=" ">
78
+ <subfield code="a">DLC</subfield>
79
+ <subfield code="c">DLC</subfield>
80
+ <subfield code="d">DLC</subfield>
81
+ </datafield>
82
+ <datafield tag="100" ind1="1" ind2=" ">
83
+ <subfield code="a">Chabon, Michael.</subfield>
84
+ </datafield>
85
+ <datafield tag="245" ind1="1" ind2="0">
86
+ <subfield code="a">Summerland /</subfield>
87
+ <subfield code="c">Michael Chabon.</subfield>
88
+ </datafield>
89
+ <datafield tag="250" ind1=" " ind2=" ">
90
+ <subfield code="a">1st ed.</subfield>
91
+ </datafield>
92
+ <datafield tag="260" ind1=" " ind2=" ">
93
+ <subfield code="a">New York :</subfield>
94
+ <subfield code="b">Miramax Books/Hyperion Books for Children,</subfield>
95
+ <subfield code="c">c2002.</subfield>
96
+ </datafield>
97
+ <datafield tag="300" ind1=" " ind2=" ">
98
+ <subfield code="a">500 p. ;</subfield>
99
+ <subfield code="c">22 cm.</subfield>
100
+ </datafield>
101
+ <datafield tag="520" ind1=" " ind2=" ">
102
+ <subfield code="a">Ethan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy.</subfield>
103
+ </datafield>
104
+ <datafield tag="650" ind1=" " ind2="1">
105
+ <subfield code="a">Fantasy.</subfield>
106
+ </datafield>
107
+ <datafield tag="650" ind1=" " ind2="1">
108
+ <subfield code="a">Baseball</subfield>
109
+ <subfield code="v">Fiction.</subfield>
110
+ </datafield>
111
+ <datafield tag="650" ind1=" " ind2="1">
112
+ <subfield code="a">Magic</subfield>
113
+ <subfield code="v">Fiction.</subfield>
114
+ </datafield>
115
+ </record>
116
+ </collection>