Created
August 6, 2010 19:01
-
-
Save rsinger/511792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'marc' | |
require 'json' | |
module MARC | |
class Record | |
# Returns a (roundtrippable) hash representation | |
def to_hash | |
record_hash = {'leader'=>self.leader, 'fields'=>[]} | |
self.fields.each do |field| | |
record_hash['fields'] << field.to_hash | |
end | |
record_hash | |
end | |
def to_json(ascii_only=false) | |
record_hash.to_json(ascii_only) | |
end | |
end | |
class ControlField | |
def to_hash | |
return {self.tag=>self.value} | |
end | |
end | |
class DataField | |
def to_hash | |
field_hash = {self.tag=>{'ind1'=>self.indicator1,'ind2'=>self.indicator2,'subfields'=>[]}} | |
self.each do |subfield| | |
field_hash[self.tag]['subfields'] << {subfield.code=>subfield.value} | |
end | |
field_hash | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment