Sha256: 00c6c834935713873177647e5b9db73a84ff1b41901ab4431bed9ae9b27099cf
Contents?: true
Size: 1.67 KB
Versions: 4
Compression:
Stored size: 1.67 KB
Contents
require 'marc/spec/queries/selector' module MARC module Spec module Queries class IndicatorValue include Selector # ------------------------------------------------------------ # Constants VALID_INDICATORS = [1, 2].freeze # ------------------------------------------------------------ # Attributes attr_reader :tag, :ind # ------------------------------------------------------------ # Initializer def initialize(ind) @ind = valid_indicator(ind) end # ------------------------------------------------------------ # Object overrides def to_s "^#{ind}" end # ------------------------------ # Applicable def can_apply?(marc_obj) %i[indicator1 indicator2].all? { |m| marc_obj.respond_to?(m) } end # ------------------------------------------------------------ # Protected methods protected # ------------------------------ # Applicable def do_apply(marc_obj) ind_val = ind_val_for(marc_obj) ind_val ? [ind_val] : [] end def equality_attrs %i[ind] end private def ind_val_for(data_field) case ind when 1 data_field.indicator1 when 2 data_field.indicator2 end end def valid_indicator(ind_val) ind = int_or_nil(ind_val) return ind if VALID_INDICATORS.include?(ind) raise ArgumentError, "Not a valid indicator: #{ind_val.inspect}" end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems