TrajectPlus
TrajectPlus is a number of useful additions to Traject
Features
New readers:
TrajectPlus::JsonReader
provide 'reader_class_name', 'TrajectPlus::JsonReader'
to_field 'title', extract_json('$.label')
TrajectPlus::CSVReader
provide 'reader_class_name', 'TrajectPlus::CSVReader'
to_field 'title', column('Record Title')
TrajectPlus::XMLReader
provide 'reader_class_name', 'TrajectPlus::XMLReader'
to_field 'title', extract_xml('/*/mods:language/mods:scriptTerm',
{ 'mods' => 'http://www.loc.gov/mods/v3' })
There are also XML macros for specific formats (MODS, TEI, FGCD):
For example:
to_field 'title', extract_mods('/*/mods:language/mods:scriptTerm')
to_field 'cho_description', extract_tei("/*/tei:teiHeader/tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:msContents/tei:summary")
extract_fgdc('/*/idinfo/citation/citeinfo/geoform')
New macros:
- transform_values
- first
- conditional
- from_settings
- match
- format
- translation_map
-
accumulate
: Streamlines creation of lambdas that need no additional parsing or filtering
to_field 'x', accumulate { |record, context| record.values }
-
copy
: Copies values from one output field to another
to_field 'x', copy('y')
-
compose
: easy create sub-transformations
compose do
to_field 'x', accumulate { |record, context| record.x }
end
# => { 'x' => [1, 2, 3]}
compose('subfield') do
to_field 'x', accumulate { |record, context| record.x }
end
# => { 'subfield' => [{ 'x' => [1, 2, 3]} ]}
compose ->(record, accumulator, context) { record.subfield } do
to_field 'x', accumulate { |subfield, context| subfield.x }
end
# => { 'x' => [1, 2, 3]}
-
transform
, supporting a variety of string methods: 'split', 'concat', 'prepend', 'gsub', 'encode', 'insert', 'strip', 'upcase', 'downcase', 'capitalize'
These can be applied to any extract function:
to_field 'title', extract: extract_xml('title'), transform: transform(gsub: ['|', ' - '])
Installation
Add this line to your application's Gemfile:
gem 'traject_plus'
And then execute:
$ bundle
Or install it yourself as:
$ gem install traject_plus
Usage
TODO: Write usage instructions here
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/traject_plus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Code of Conduct
Everyone interacting in the TrajectPlus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.