Class: ModsDisplay::HTML
- Inherits:
-
Object
show all
- Defined in:
- lib/mods_display/html.rb
Instance Method Summary
collapse
Constructor Details
#initialize(config, xml, klass) ⇒ HTML
3
4
5
6
7
8
|
# File 'lib/mods_display/html.rb', line 3
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
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/mods_display/html.rb', line 40
def method_missing(method_name, *args, &block)
if to_s.respond_to?(method_name)
to_html.send(method_name, *args, &block)
elsif method_name == :subTitle || mods_display_fields.include?(method_name)
field = mods_field(@xml, method_name)
return field if (args.dig(0, :raw))
field.fields
else
super
end
end
|
Instance Method Details
#body ⇒ Object
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.
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/mods_display/html.rb', line 20
def body
output = '<dl>'
body_fields = mods_display_fields.dup
body_fields[0] = :subTitle
body_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
|
#title ⇒ Object
10
11
12
13
14
15
|
# File 'lib/mods_display/html.rb', line 10
def title
unless mods_field(@xml, :title).fields.empty?
return mods_field(@xml, :title).fields.first.values
end
''
end
|
#to_html ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/mods_display/html.rb', line 31
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
|