module BerkeleyLibrary::TIND::Export::Filter

Constants

DO_NOT_EDIT
DO_NOT_EDIT_FIELDS
DO_NOT_EDIT_SUBFIELDS
DO_NOT_EXPORT_FIELDS
DO_NOT_EXPORT_SUBFIELDS

Public Class Methods

can_edit?(tag, ind1, ind2, code) click to toggle source
# File lib/berkeley_library/tind/export/filter.rb, line 31
def can_edit?(tag, ind1, ind2, code)
  DO_NOT_EDIT.none? { |f| excludes?(f, tag, ind1, ind2, code) }
end
can_export_data_field?(df) click to toggle source
# File lib/berkeley_library/tind/export/filter.rb, line 18
def can_export_data_field?(df)
  !exportable_subfield_codes(df).empty?
end
can_export_tag?(tag) click to toggle source
# File lib/berkeley_library/tind/export/filter.rb, line 14
def can_export_tag?(tag)
  !DO_NOT_EXPORT_FIELDS.include?(tag)
end
exportable_subfield_codes(df) click to toggle source
# File lib/berkeley_library/tind/export/filter.rb, line 22
def exportable_subfield_codes(df)
  tag, ind1, ind2 = decompose_data_field(df)
  DO_NOT_EXPORT_FIELDS.each { |f| return [] if excludes?(f, tag, ind1, ind2) }

  df.subfield_codes.reject do |code|
    DO_NOT_EXPORT_SUBFIELDS.any? { |f| excludes?(f, tag, ind1, ind2, code) }
  end
end

Private Class Methods

decompose_data_field(df) click to toggle source
# File lib/berkeley_library/tind/export/filter.rb, line 37
def decompose_data_field(df)
  [df.tag, df.indicator1, df.indicator2]
end
excludes?(f, tag, ind1, ind2, code = nil) click to toggle source

TODO: test this more carefully

# File lib/berkeley_library/tind/export/filter.rb, line 42
def excludes?(f, tag, ind1, ind2, code = nil)
  return f == tag if f.size == 3

  excludes_tag = f.start_with?(tag) && f[3] == ind1 && f[4] == ind2
  code ? excludes_tag && code : excludes_tag
end