Project

marcspec

0.0
No commit activity in last 3 years
No release in over 3 years
Relies on marc4j4r, based on work in solrmarc
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
>= 0
>= 0
 Project Readme

marcspec

The MARCSpec contains classes designed to make it (relatively) easy to specify a data field (my use case specifically is solr) in terms of sets of MARC fields and subfields.

It currently requires the use of marc4j4r and hence JRuby, but I'm going to work on making a compatibility layer with ruby-marc now that the 0.4 version is out.

Usage

require 'rubygems'
require 'marcspec'
require 'marc4j4r'
require 'marc2solr/marc2solr_custom' # get the custom functions

ss = MARCSpec::SpecSet.build do
  field('id') {
    spec('001')
    firstOnly # only take the first 001
  }
  field('title') {
    spec('245a') # just the a
    spec('245ab') # just the ab
    spec('245')   # the whole thing
  }
  field('lccn') {
    spec('010a')
  }
  custom('oclc') { # use a custom function
    function(:valsByPattern) {
      mod MARC2Solr::Custom
      args '035', 'a', /(?:oclc|ocolc|ocm|ocn).*?(\d+)/i, 1
    }
  }
end

reader = MARC4J4R::Reader.new('mymarc.mrc', :strictmarc)

reader.each do |r|
  h = ss.hash_from_marc(r)
  # or doc = ss_doc_from_marc(r) # gets a SolrInputDocument
  
  puts h['lccn'][0] # the first lccn
  h['title'].each do |t|
    puts t
  end
  
end

Docs and examples

Docs are hosted at the [[wiki|http://github.com/billdueber/marcspec/wiki/]]

Documented samples are available as part of the marc2solr_example project -- look in the simple_sample area to start with.

##Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2010 BillDueber. See LICENSE for details.