Class: Europeana::Blacklight::Document

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, Blacklight::Document, Blacklight::Document::ActiveModelShim, LangMaps, MoreLikeThis, Relations
Defined in:
app/models/europeana/blacklight/document.rb,
app/models/europeana/blacklight/document/lang_maps.rb,
app/models/europeana/blacklight/document/relations.rb,
app/models/europeana/blacklight/document/more_like_this.rb

Overview

A Europeana document

Defined Under Namespace

Modules: LangMaps, MoreLikeThis, Relations

Constant Summary

Constants included from LangMaps

LangMaps::DEPRECATED_ISO_LANG_CODES, LangMaps::NON_ISO_LANG_CODES

Instance Attribute Summary collapse

Attributes included from Relations

#relations

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Relations

#extract_relations, #fetch_through_relation, #field_in_relation?, #has?, #has_relation?, #key?, #method_missing, #nested_field_container, #nested_field_key

Methods included from MoreLikeThis

#more_like_this_query

Methods included from LangMaps

#dereferenced_lang_map_value, #known_lang_map_key?, #lang_map?, #lang_map_value, #localize_lang_map

Constructor Details

#initialize(source_doc = {}, response = nil, root = self) ⇒ Document

Returns a new instance of Document.



27
28
29
30
31
# File 'app/models/europeana/blacklight/document.rb', line 27

def initialize(source_doc = {}, response = nil, root = self)
  fields, @relations = extract_relations(source_doc)
  @root = root
  super(fields, response)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Europeana::Blacklight::Document::Relations

Instance Attribute Details

#provider_idObject



73
74
75
# File 'app/models/europeana/blacklight/document.rb', line 73

def provider_id
  @provider_id ||= id.to_s.split('/')[1]
end

#record_idObject



77
78
79
# File 'app/models/europeana/blacklight/document.rb', line 77

def record_id
  @record_id ||= id.to_s.split('/')[2]
end

#rootObject (readonly)

Returns the value of attribute root.



16
17
18
# File 'app/models/europeana/blacklight/document.rb', line 16

def root
  @root
end

Class Method Details

.model_nameObject



20
21
22
23
24
# File 'app/models/europeana/blacklight/document.rb', line 20

def model_name
  @_model_name ||= begin
    ActiveModel::Name.new(self, nil, 'Document')
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object



88
89
90
91
92
93
94
# File 'app/models/europeana/blacklight/document.rb', line 88

def as_json(options = {})
  super.tap do |json|
    relations.each do |k, v|
      json[k] = v.as_json
    end
  end
end

#fetch(key, *default) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/models/europeana/blacklight/document.rb', line 38

def fetch(key, *default)
  value = if has_relation?(key)
    relations[key]
  elsif field_in_relation?(key)
    fetch_through_relation(key, *default)
  else
    super
  end
  localize_lang_map(value)
end

#idObject



33
34
35
36
# File 'app/models/europeana/blacklight/document.rb', line 33

def id
  return @id unless @id.nil?
  @id = (self['id'] || self['about']).sub(%r{^//}, '/')
end

#persisted?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/europeana/blacklight/document.rb', line 61

def persisted?
  true
end

#private?(_exhibit) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/europeana/blacklight/document.rb', line 65

def private?(_exhibit)
  false
end

#public?(_exhibit) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/europeana/blacklight/document.rb', line 69

def public?(_exhibit)
  true
end

#rankObject

This document’s position in a set of search results, if applicable



83
84
85
86
# File 'app/models/europeana/blacklight/document.rb', line 83

def rank
  return nil unless response.present? & response.key?('items')
  response.documents.find_index { |doc| doc == self } + response.start + 1
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/europeana/blacklight/document.rb', line 49

def respond_to?(*args)
  (args.size == 1 && relations.key?(*args)) || super
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/europeana/blacklight/document.rb', line 53

def respond_to_missing?(*args)
  (args.size == 1 && relations.key?(*args)) || super
end

#to_paramObject



57
58
59
# File 'app/models/europeana/blacklight/document.rb', line 57

def to_param
  "#{provider_id}/#{record_id}"
end