Class: ContentDm::Record
- Inherits:
-
Object
- Object
- ContentDm::Record
- Defined in:
- lib/contentdm/record.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #img_href(opts = {}) ⇒ Object
-
#initialize(data, source) ⇒ Record
constructor
A new instance of Record.
- #mapper ⇒ Object
- #permalink ⇒ Object
- #permalink=(value) ⇒ Object
- #thumbnail_href ⇒ Object
-
#to_html(opts = {}) ⇒ Object
Serialize the Record to an HTML string.
-
#to_xml(opts = {}) ⇒ Object
Serialize the Record to a Qualified Dublin Core XML string.
Constructor Details
#initialize(data, source) ⇒ Record
Returns a new instance of Record.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/contentdm/record.rb', line 7 def initialize(data, source) @metadata = data.dup @source = source # Account for bug in single-record output # parts = self.permalink.split # if parts.length > 1 # self.permalink = @source[:base_uri].merge(parts.last).to_s # end (collection, record_id) = @metadata['dc.identifier'][-1].scan(/\?\/(.+),([0-9]+)$/).flatten @source[:collection] = collection @source[:id] = record_id.to_i self.permalink = @source[:base_uri].merge("/u?/#{collection},#{record_id}").to_s end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/contentdm/record.rb', line 5 def @metadata end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/contentdm/record.rb', line 5 def source @source end |
Instance Method Details
#img_href(opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/contentdm/record.rb', line 23 def img_href(opts = {}) params = { 'CISOROOT' => "/#{@source[:collection]}", 'CISOPTR' => @source[:id], 'DMSCALE' => 100, 'DMWIDTH' => 0, 'DMHEIGHT' => 0, 'DMX' => 0, 'DMY' => 0, 'DMTEXT' => '', 'DMTHUMB' => '', 'DMROTATE' => 0 } opts.each_pair { |k,v| case k when :width then params['DMWIDTH'] = v when :height then params['DMHEIGHT'] = v when :scale then params['DMSCALE'] = v else params[k] = v end } query = params.collect { |k,v| "#{k}=#{::URI.encode(v.to_s)}" }.join('&') @source[:base_uri].merge("cgi-bin/getimage.exe?#{query}") end |
#mapper ⇒ Object
65 66 67 |
# File 'lib/contentdm/record.rb', line 65 def mapper Mapper.from(@source[:base_uri],@source[:collection]) || GenericMapper.new end |
#permalink ⇒ Object
57 58 59 |
# File 'lib/contentdm/record.rb', line 57 def permalink @metadata['dc.identifier'][-1] end |
#permalink=(value) ⇒ Object
61 62 63 |
# File 'lib/contentdm/record.rb', line 61 def permalink=(value) @metadata['dc.identifier'][-1] = value end |
#thumbnail_href ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/contentdm/record.rb', line 48 def thumbnail_href params = { 'CISOROOT' => "/#{@source[:collection]}", 'CISOPTR' => @source[:id], } query = params.collect { |k,v| "#{k}=#{::URI.encode(v.to_s)}" }.join('&') @source[:base_uri].merge("cgi-bin/thumbnail.exe?#{query}") end |
#to_html(opts = {}) ⇒ Object
Serialize the Record to an HTML string. If a Mapper has been initialized for the Record’s owning collection, it will be used. Otherwise, the GenericMapper will be used.
79 80 81 |
# File 'lib/contentdm/record.rb', line 79 def to_html(opts = {}) mapper.to_html(self, opts) end |
#to_xml(opts = {}) ⇒ Object
Serialize the Record to a Qualified Dublin Core XML string. If a Mapper has been initialized for the Record’s owning collection, it will be used. Otherwise, the GenericMapper will be used.
72 73 74 |
# File 'lib/contentdm/record.rb', line 72 def to_xml(opts = {}) mapper.to_xml(self, opts) end |