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.

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)


51
52
53
54
55
56
57
58
59
60
# File 'lib/catalog/entry_item.rb', line 51

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&.source&.year_suffix
  @pages = citation&.source&.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

Returns See Catalog::Entry#first_item?.

Returns:

  • (Boolean)

    See Catalog::Entry#first_item?



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

def is_first
  @is_first
end

#is_lastBoolean

Returns See Catalog::Entry#last_item?.

Returns:

  • (Boolean)

    See Catalog::Entry#last_item?



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

def is_last
  @is_last
end

#matches_current_targetBoolean

Returns does this match the target Entry.

Returns:

  • (Boolean)

    does this match the target Entry



48
49
50
# File 'lib/catalog/entry_item.rb', line 48

def matches_current_target
  @matches_current_target
end

#nomenclature_dateDate

!!TODO: we should not be checking at this point. Assignment must happen outside this module.

Returns:

  • (Date)


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

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)


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

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



32
33
34
# File 'lib/catalog/entry_item.rb', line 32

def to_html_method
  @to_html_method
end

#year_suffixString

Source.year_suffix

Returns:

  • (String)


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

def year_suffix
  @year_suffix
end

Instance Method Details

#base_data_attributesObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/catalog/entry_item.rb', line 66

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)


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

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

#cited_classString (protected)

Returns:

  • (String)


145
146
147
148
149
150
151
# File 'lib/catalog/entry_item.rb', line 145

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

#data_attributesObject

See Subclasses for extensions



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

def data_attributes
  base_data_attributes
end

#html_helperObject



62
63
64
# File 'lib/catalog/entry_item.rb', line 62

def html_helper
  :object_tag
end

#in_source?(target_source) ⇒ Boolean

TODO: optimize indecies so this is not needed.

Returns:

  • (Boolean)


138
139
140
# File 'lib/catalog/entry_item.rb', line 138

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



113
114
115
# File 'lib/catalog/entry_item.rb', line 113

def object_class
  object.class.name
end

#originString

Returns:

  • (String)


118
119
120
121
122
123
124
125
# File 'lib/catalog/entry_item.rb', line 118

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

#references_self?Boolean

Returns:

  • (Boolean)


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

def references_self?
  object == base_object
end

#sourceSource?

Returns:



93
94
95
# File 'lib/catalog/entry_item.rb', line 93

def source
  citation&.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



129
130
131
132
133
134
135
# File 'lib/catalog/entry_item.rb', line 129

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