Class: ModsDisplay::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/mods_display/html.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, xml, klass) ⇒ HTML

Returns a new instance of HTML.



4
5
6
7
8
9
# File 'lib/mods_display/html.rb', line 4

def initialize(config, xml, klass)
  @config = config
  @stanford_mods = xml
  @xml = xml.mods_ng_xml
  @klass = klass
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/mods_display/html.rb', line 43

def method_missing(method_name, *args, &block)
  if to_s.respond_to?(method_name)
    to_html.send(method_name, *args, &block)
  elsif mods_display_fields.include?(method_name)
    mods_field(@xml, method_name).fields
  else
    super
  end
end

Instance Attribute Details

#bodyObject (readonly)

Need to figure out how to get the 1st title out of the list. Maybe have a separate class that will omit the first tite natively and replace the first key in the the fields list with that.



21
22
23
# File 'lib/mods_display/html.rb', line 21

def body
  @body
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/mods_display/html.rb', line 3

def title
  @title
end

Instance Method Details

#to_htmlObject



34
35
36
37
38
39
40
41
# File 'lib/mods_display/html.rb', line 34

def to_html
  output = '<dl>'
  mods_display_fields.each do |field_key|
    field = mods_field(@xml, field_key)
    output << field.to_html unless field.nil? || field.to_html.nil?
  end
  output << '</dl>'
end