Class: Stanford::Mods::Imprint

Inherits:
Object
  • Object
show all
Defined in:
lib/stanford-mods/imprint.rb

Overview

Get the imprint information from originInfo elements (and sub elements) to create display strings

This code is adapted from the mods_display gem. In a perfect world, this code would make use of the date_parsing class instead of reimplementing pieces of it; however, the date_parsing class only does years, and this does finer tuned dates and also reformats them according to the encoding.

Defined Under Namespace

Classes: DateRange, DateValue

Constant Summary collapse

BCE_CHAR_SORT_MAP =
{ '0' => '9', '1' => '8', '2' => '7', '3' => '6', '4' => '5', '5' => '4', '6' => '3', '7' => '2', '8' => '1', '9' => '0' }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Imprint

Returns a new instance of Imprint.

Parameters:

  • an (Nokogiri::XML::Node)

    originInfo node



18
19
20
# File 'lib/stanford-mods/imprint.rb', line 18

def initialize(element)
  @element = element
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



15
16
17
# File 'lib/stanford-mods/imprint.rb', line 15

def element
  @element
end

Instance Method Details

#dates(date_field_keys = [:dateIssued, :dateCreated, :dateCaptured, :copyrightDate]) ⇒ Object

array of parsed but unformattted date values, for a given list of elements to pull data from



42
43
44
45
46
47
48
49
# File 'lib/stanford-mods/imprint.rb', line 42

def dates(date_field_keys = [:dateIssued, :dateCreated, :dateCaptured, :copyrightDate])
  date_field_keys.map do |date_field|
    next unless element.respond_to?(date_field)

    date_elements = element.send(date_field)
    parse_dates(date_elements) if date_elements.present?
  end.compact.flatten
end

#display_strString

Returns an imprint statement from a single originInfo element.

Returns:

  • (String)

    an imprint statement from a single originInfo element



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/stanford-mods/imprint.rb', line 27

def display_str
  edition = edition_vals_str
  place = place_vals_str
  publisher = publisher_vals_str
  dates = date_str

  place_pub = compact_and_join_with_delimiter([place, publisher], ' : ')
  edition_place_pub = compact_and_join_with_delimiter([edition, place_pub], ' - ')
  ed_place_pub_dates = compact_and_join_with_delimiter([edition_place_pub, dates], ', ')

  ed_place_pub_dates
end

#edition_vals_strObject

called by mods_display gem



62
63
64
65
66
# File 'lib/stanford-mods/imprint.rb', line 62

def edition_vals_str
  element.edition.reject do |e|
    e.text.strip.empty?
  end.map(&:text).join(' ').strip
end

#imprint_statementsObject



22
23
24
# File 'lib/stanford-mods/imprint.rb', line 22

def imprint_statements
  display_str
end

#publisher_vals_strObject

called by mods_display gem



52
53
54
55
56
57
58
59
# File 'lib/stanford-mods/imprint.rb', line 52

def publisher_vals_str
  return if element.publisher.text.strip.empty?

  publishers = element.publisher.reject do |p|
    p.text.strip.empty?
  end.map(&:text)
  compact_and_join_with_delimiter(publishers, ' : ')
end