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.



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

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



75
76
77
# File 'app/models/europeana/blacklight/document.rb', line 75

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

#record_idObject



79
80
81
# File 'app/models/europeana/blacklight/document.rb', line 79

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

#rootObject (readonly)

Returns the value of attribute root.



18
19
20
# File 'app/models/europeana/blacklight/document.rb', line 18

def root
  @root
end

Class Method Details

.model_nameObject



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

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

Instance Method Details

#as_json(options = {}) ⇒ Object



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

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



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

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



35
36
37
38
# File 'app/models/europeana/blacklight/document.rb', line 35

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

#persisted?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/europeana/blacklight/document.rb', line 63

def persisted?
  true
end

#private?(_exhibit) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/europeana/blacklight/document.rb', line 67

def private?(_exhibit)
  false
end

#public?(_exhibit) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/europeana/blacklight/document.rb', line 71

def public?(_exhibit)
  true
end

#rankObject

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



85
86
87
88
# File 'app/models/europeana/blacklight/document.rb', line 85

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)


51
52
53
# File 'app/models/europeana/blacklight/document.rb', line 51

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

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/europeana/blacklight/document.rb', line 55

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

#to_paramObject



59
60
61
# File 'app/models/europeana/blacklight/document.rb', line 59

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