Module: Cul::Hydra::Solrizer::ModsFieldable::ClassMethods

Included in:
Cul::Hydra::Solrizer::ModsFieldable
Defined in:
lib/cul_hydra/solrizer/mods_fieldable.rb

Instance Method Summary collapse

Instance Method Details

#map_field(field_key, map_key) ⇒ Object



14
15
16
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 14

def map_field(field_key, map_key)
  value_mapper.map_field(field_key, map_key)
end

#map_value(field_key, value_key) ⇒ Object



18
19
20
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 18

def map_value(field_key, value_key)
  value_mapper.map_value(field_key, value_key)
end

#maps_field?(field_key) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 22

def maps_field?(field_key)
  value_mapper.maps_field? field_key
end

#normalize(t, strip_punctuation = false) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 26

def normalize(t, strip_punctuation=false)
  # strip whitespace
  n_t = t.dup.strip
  # collapse intermediate whitespace
  n_t.gsub!(/\s+/, ' ')
  # pull off paired punctuation, and any leading punctuation
  if strip_punctuation
    # strip brackets
    n_t = n_t.sub(/^\((.*)\)$/, "\\1")
    n_t = n_t.sub(/^\{(.*)\}$/, "\\1")
    n_t = n_t.sub(/^\[(.*)\]$/, "\\1")
    n_t = n_t.sub(/^<(.*)>$/, "\\1")
    # strip quotes
    n_t = n_t.sub(/^"(.*)"$/, "\\1")
    n_t = n_t.sub(/^'(.*)'$/, "\\1")
    is_negative_number = n_t =~ /^-\d+$/
    n_t = n_t.sub(/^[[:punct:]]+/, '')
    # this may have 'created' leading/trailing space, so strip
    n_t.strip!
    n_t = '-' + n_t if is_negative_number
  end
  n_t
end

#role_text_to_solr_field_name(role_text) ⇒ Object



50
51
52
53
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 50

def role_text_to_solr_field_name(role_text)
  role_text = normalize(role_text, false)
  ('role_' + role_text.gsub(/[^A-z]/, '_').downcase + '_ssim').gsub(/_+/, '_')
end

#value_mapper(maps = nil) ⇒ Object



10
11
12
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 10

def value_mapper(maps=nil)
  @value_mapper ||= ValueMapper.new(maps)
end