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.

Instance Method Summary collapse

Constructor Details

#initialize(originInfo_ng_nodeset) ⇒ Imprint


12
13
14
# File 'lib/stanford-mods/imprint.rb', line 12

def initialize(originInfo_ng_nodeset)
  @originInfo_ng_nodeset = originInfo_ng_nodeset
end

Instance Method Details

#display_strObject


36
37
38
# File 'lib/stanford-mods/imprint.rb', line 36

def display_str
  imprint_statements.join('; ') if imprint_statements.present?
end

#imprint_statementsObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stanford-mods/imprint.rb', line 19

def imprint_statements
  results = []
  @originInfo_ng_nodeset.each do |origin_info_node|
    edition = edition_vals_str(origin_info_node)
    place = place_vals_str(origin_info_node)
    publisher = publisher_vals_str(origin_info_node)
    dates = date_str(origin_info_node)

    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], ', ')

    results << ed_place_pub_dates unless ed_place_pub_dates.empty?
  end
  results
end

#publication_date_for_sliderObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/stanford-mods/imprint.rb', line 41

def publication_date_for_slider
  @originInfo_ng_nodeset.map do |origin_info_node|

    date_elements = if origin_info_node.as_object.first.key_dates.any?
                      origin_info_node.as_object.first.key_dates.map(&:as_object).map(&:first)
                    else
                      date_field_keys.map do |date_field|
                        next unless origin_info_node.respond_to?(date_field)
                        date_elements = origin_info_node.send(date_field)
                        date_elements.map(&:as_object).map(&:first) if date_elements.any?
                      end.first
                    end

    if date_elements.nil? || date_elements.none?
      []
    elsif date_elements.find(&:start?) && date_elements.find(&:end?)
      start_date = date_elements.find(&:start?)
      end_date = date_elements.find(&:end?)

      (start_date.as_range.min.year..end_date.as_range.max.year).to_a
    elsif date_elements.find(&:start?)
      start_date = date_elements.find(&:start?)

      (start_date.as_range.min.year..Time.now.year).to_a
    elsif date_elements.one?
      date_elements.first.to_a.map(&:year)
    else
      date_elements.map { |v| v.to_a.map(&:year) }.flatten
    end
  end.flatten
end