def marc_era_facet
      ordinary_fields_spec = "600y:610y:611y:630y:648ay:650y:654y:656y:690y"
      special_fields_spec = "651:691"
      separator = ": "

      extractor_ordinary_fields = MarcExtractor.new(ordinary_fields_spec)
      extractor_special_fields  = MarcExtractor.new(special_fields_spec)

      lambda do |record, accumulator|
        # straightforward ones


        accumulator.concat( extractor_ordinary_fields.extract(record).collect do |v|
          # May have a period we have to remove, if it was at end of tag
          v.sub(/\. *\Z/, '')
        end)

        # weird ones
        special_fields_regex = /\A\s*.+,\s+(ca.\s+)?\d\d\d\d?(-\d\d\d\d?)?( B\.C\.)?[.,; ]*\Z/
        extractor_special_fields.each_matching_line(record) do |field, spec, extractor|
          field.subfields.each do |sf|
            next unless sf.code == 'y'
            if special_fields_regex.match(sf.value)
              # it's our pattern, add the $a in please
              accumulator << "#{field['a']}#{separator}#{sf.value.sub(/\. *\Z/, '')}"
            else
              accumulator << sf.value.sub(/\. *\Z/, '')
            end
          end
        end
        accumulator.uniq!
      end
    end
def marc_era_facet
      ordinary_fields_spec = "600y:610y:611y:630y:648ay:650y:654y:656y:690y"
      special_fields_spec = "651:691"
      separator = ": "

      extractor_ordinary_fields = MarcExtractor.new(ordinary_fields_spec)
      extractor_special_fields  = MarcExtractor.new(special_fields_spec)

      lambda do |record, accumulator|
        # straightforward ones


        accumulator.concat( extractor_ordinary_fields.extract(record).collect do |v|
          # May have a period we have to remove, if it was at end of tag
          v.sub(/\. *\Z/, '')
        end)

        # weird ones
        special_fields_regex = /\A\s*.+,\s+(ca.\s+)?\d\d\d\d?(-\d\d\d\d?)?( B\.C\.)?[.,; ]*\Z/
        extractor_special_fields.each_matching_line(record) do |field, spec, extractor|
          field.subfields.each do |sf|
            next unless sf.code == 'y'
            if special_fields_regex.match(sf.value)
              # it's our pattern, add the $a in please
              accumulator << "#{field['a']}#{separator}#{sf.value.sub(/\. *\Z/, '')}"
            else
              accumulator << sf.value.sub(/\. *\Z/, '')
            end
          end
        end
        accumulator.uniq!
      end
    end
Opinionated routine to create values for a chronology/era facet out of
 LCSH chron subdivisions. Does some normalization:
 for 651 with a chron facet fitting the form
 "aaaaa, yyyy-yyyy", it will add in the $a. For instance:
 651   a| United States x| History y| Civil War, 1861-1865
 --> "United States: Civil War, 1861-1865"