Sha256: 9ad9c9583cde4e2f07b855ecc277f8f1939141f283be4c5c9993941d3ac9f570

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

class ModsDisplay::Title < ModsDisplay::Field

  
  def fields
    return_values = []
    @value.each do |val|
      if displayForm(val)
        return_values << ModsDisplay::Values.new(:label => displayLabel(val) || title_label(val), :values => [displayForm(val).text])
      else
        nonSort = nil
        title = nil
        subTitle = nil
        nonSort = val.nonSort.text.strip unless val.nonSort.text.strip.empty?
        title = val.title.text.strip unless val.title.text.strip.empty?
        subTitle = val.subTitle.text unless val.subTitle.text.strip.empty?
        preSubTitle = [nonSort, title].compact.join(" ")
        preSubTitle = nil if preSubTitle.strip.empty?
        preParts = [preSubTitle, subTitle].compact.join(" : ")
        preParts = nil if preParts.strip.empty?
        parts = val.children.select do |child|
          ["partName", "partNumber"].include?(child.name)
        end.map do |child|
          child.text
        end.compact.join(", ")
        parts = nil if parts.strip.empty?
        return_values << ModsDisplay::Values.new(:label => displayLabel(val) || title_label(val), :values => [[preParts, parts].compact.join(". ")])
      end
    end
    return_values
  end

  private

  def title_label(element)
    if (element.attributes["type"].respond_to?(:value) and
        title_labels.has_key?(element.attributes["type"].value))
      return title_labels[element.attributes["type"].value]
    end
    "Title"
  end

  def title_labels
    {"abbreviated" => "Abbreviated Title",
     "translated"  => "Translated Title",
     "alternative" => "Alternative Title",
     "uniform"     => "Uniform Title"}
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mods_display-0.0.1.beta6 lib/mods_display/fields/title.rb
mods_display-0.0.1.beta5 lib/mods_display/fields/title.rb
mods_display-0.0.1.beta4 lib/mods_display/fields/title.rb
mods_display-0.0.1.beta3 lib/mods_display/fields/title.rb
mods_display-0.0.1.beta2 lib/mods_display/fields/title.rb
mods_display-0.0.1.beta1 lib/mods_display/fields/title.rb