Skip to content

Instantly share code, notes, and snippets.

@rsinger
Created August 6, 2010 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsinger/511792 to your computer and use it in GitHub Desktop.
Save rsinger/511792 to your computer and use it in GitHub Desktop.
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