Class: Catalog::EntryItem

Inherits:
Object
  • Object
show all
Defined in:
lib/catalog/entry_item.rb

Overview

A Catalog::EntryItem corresponds to a single row in the catalog. It can be thought of as a chronological entry typically 1:1 with some Citation.

Direct Known Subclasses

Nomenclature::EntryItem, Otu::EntryItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object: nil, base_object: nil, citation: nil, nomenclature_date: nil, year_suffix: nil, pages: nil, citation_date: nil, current_target: nil) ⇒ EntryItem

Returns a new instance of EntryItem.

Parameters:

  • args (Hash)


47
48
49
50
51
52
53
54
55
56
# File 'lib/catalog/entry_item.rb', line 47

def initialize(object: nil, base_object: nil, citation: nil, nomenclature_date: nil, year_suffix: nil, pages: nil, citation_date: nil, current_target: nil)
  raise if object.nil?
  @object = object
  @base_object = base_object 
  @nomenclature_date = nomenclature_date
  @year_suffix = citation.try(:source).try(:year_suffix)
  @pages =  citation.try(:source).try(:pages)
  @citation = citation
  @matches_current_target = current_target
end

Instance Attribute Details

#base_objectObject

The visualized element of this entry item, e.g. the subject taxon name of a taxon name relationship



5
6
7
# File 'lib/catalog/entry_item.rb', line 5

def base_object
  @base_object
end

#citationObject

Optional, should be provided explicitly



11
12
13
# File 'lib/catalog/entry_item.rb', line 11

def citation
  @citation
end

#is_firstBoolean

Computed/cached attributes, built on `build` of Entry

Returns:

  • (Boolean)

    See Catalog::Entry#first_item?



36
37
38
# File 'lib/catalog/entry_item.rb', line 36

def is_first
  @is_first
end

#is_lastBoolean

Returns See Catalog::Entry#last_item?.

Returns:

  • (Boolean)

    See Catalog::Entry#last_item?



40
41
42
# File 'lib/catalog/entry_item.rb', line 40

def is_last
  @is_last
end

#matches_current_targetBoolean

Returns does this match the target Entry.

Returns:

  • (Boolean)

    does this match the target Entry



44
45
46
# File 'lib/catalog/entry_item.rb', line 44

def matches_current_target
  @matches_current_target
end

#nomenclature_dateDate

Returns:

  • (Date)


17
18
19
# File 'lib/catalog/entry_item.rb', line 17

def nomenclature_date
  @nomenclature_date
end

#objectObject

The source of this entry item, e.g. a TaxonNameRelationship



8
9
10
# File 'lib/catalog/entry_item.rb', line 8

def object
  @object
end

#pagesString

Source.pages

Returns:

  • (String)


25
26
27
# File 'lib/catalog/entry_item.rb', line 25

def pages
  @pages
end

#to_html_methodSymbol

Returns a pointer to a method in /app/helpers.

Returns:

  • (Symbol)

    a pointer to a method in /app/helpers



29
30
31
# File 'lib/catalog/entry_item.rb', line 29

def to_html_method
  @to_html_method
end

#year_suffixString

Source.year_suffix

Returns:

  • (String)


21
22
23
# File 'lib/catalog/entry_item.rb', line 21

def year_suffix
  @year_suffix
end

Instance Method Details

#base_data_attributesObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/catalog/entry_item.rb', line 62

def base_data_attributes
  {
    'history-origin' => origin,
    'history-object-id' => object.to_global_id.to_s,
    'history-year' => nomenclature_date&.year || 'unknown',
    'history-is-first' => is_first,
    'history-is-last' => is_last, 
    'history-is-cited' => (citation ? true : false),
    'history-is-current-target' => matches_current_target
  }
end

#cited?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/catalog/entry_item.rb', line 84

def cited?
  !citation.nil? # object.class.name == 'Citation'
end

#cited_classString (protected)

Returns:

  • (String)


137
138
139
140
141
142
143
# File 'lib/catalog/entry_item.rb', line 137

def cited_class
  if citation
    citation.annotated_object.class.name
  else
    object.class.name
  end
end

#data_attributesObject

See Subclasses for extensions



79
80
81
# File 'lib/catalog/entry_item.rb', line 79

def data_attributes
  base_data_attributes
end

#html_helperObject



58
59
60
# File 'lib/catalog/entry_item.rb', line 58

def html_helper
  :object_tag
end

#in_source?(target_source) ⇒ Boolean

TODO: optimize indecies so this is not needed.

Returns:

  • (Boolean)


130
131
132
# File 'lib/catalog/entry_item.rb', line 130

def in_source?(target_source)
  source == target_source
end

#object_classString

Returns do not update with base_class.

Returns:

  • (String)

    do not update with base_class



105
106
107
# File 'lib/catalog/entry_item.rb', line 105

def object_class
  object.class.name
end

#originString

Returns:

  • (String)


110
111
112
113
114
115
116
117
# File 'lib/catalog/entry_item.rb', line 110

def origin
  case object_class
  when /TaxonNameRelationship/
    'taxon_name_relationship'
  else
    object_class.tableize.singularize.humanize.downcase
  end
end

#references_self?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/catalog/entry_item.rb', line 74

def references_self?
  object == base_object 
end

#sourceSource?

Returns:



89
90
91
# File 'lib/catalog/entry_item.rb', line 89

def source
  citation.try(:source)
end

#topicsArray of Topic

Returns the topics on this object for this Citation/Source combination only.

Returns:

  • (Array of Topic)

    the topics on this object for this Citation/Source combination only



121
122
123
124
125
126
127
# File 'lib/catalog/entry_item.rb', line 121

def topics
  t = []
  if source
    t += citation.topics 
  end
  t.uniq
end