Skip to content

Commit

Permalink
is_subsequent -> is_first; filtering intents; data attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Dec 4, 2019
1 parent 1862bb7 commit 6e50964
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 87 deletions.
8 changes: 4 additions & 4 deletions app/helpers/taxon_names/catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def nomenclature_catalog_li_tag_data_attributes(nomenclature_catalog_item)
data = {
'history-origin' => n.origin,
'history-object-id' => n.object.id,
'history-valid-name' => n.is_valid_name? && !n.is_subsequent?,
'history-is-subsequent' => n.is_subsequent?
'history-valid-name' => n.is_valid_name? && n.is_first, # is_subsequent?,
'history-is-subsequent' => !n.is_first # is_subsequent?
}
data
end
Expand Down Expand Up @@ -118,7 +118,7 @@ def history_other_name(catalog_item, reference_taxon_name)
def history_statuses(nomenclature_catalog_entry_item)
i = nomenclature_catalog_entry_item
s = i.base_object.taxon_name_classifications_for_statuses
return nil if (s.empty? || i.is_subsequent?)
return nil if (s.empty? || !i.is_first) # is_subsequent?
return nil if i.from_relationship?

content_tag(:span, class: [:history__statuses]) do
Expand Down Expand Up @@ -166,7 +166,7 @@ def history_in_taxon_name(t, c)
end

def history_type_material(entry_item)
return nil if entry_item.object_class != 'Protonym' || entry_item.is_subsequent?
return nil if entry_item.object_class != 'Protonym' || !entry_item.is_first # is_subsequent?
content_tag(:span, ' '.html_safe + type_taxon_name_relationship_tag(entry_item.base_object.type_taxon_name_relationship), class: 'history__type_information')
end

Expand Down
10 changes: 4 additions & 6 deletions app/views/otus/timeline.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ json.topics do
json.array! @catalog.topics.collect{|t| {t.to_global_id.to_s => { name: t.name, css_color: t.css_color} }}
end

json.sources do
json.array! @catalog.sources.collect{|s| { s.metamorphosize.to_global_id.to_s => { cached: s.cached, objects: @catalog.objects_for_source(s).collect{|o| o.object.to_global_id.to_s } }}}
end



json.items do
json.array! @catalog.items_chronologically do |i|
json.label_html send(i.html_helper, i)
Expand All @@ -32,3 +26,7 @@ json.items do
end
end
end

json.sources do
json.array! @catalog.sources.collect{|s| { s.metamorphosize.to_global_id.to_s => { cached: s.cached, objects: @catalog.objects_for_source(s).collect{|o| o.object.to_global_id.to_s } }}}
end
9 changes: 4 additions & 5 deletions lib/catalog/entry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# A Catalog::Entry has many entry items. Together CatalogEntrys form a Catalog
# A Catalog::Entry has many entry items. Together Catalog::Entries form a Catalog
class Catalog::Entry

# The target object for this entry
Expand Down Expand Up @@ -52,7 +52,6 @@ def index_items
true
end


# @return Boolean
# Named "first` to avoid conflice with `citation#is_original`
# Returns true if
Expand All @@ -69,7 +68,7 @@ def first_item?(item)
return true if item.citation.is_original?
return true if !original_citation_present? && o.index(item) == 0

false
false
end

def original_citation_present?
Expand All @@ -81,13 +80,13 @@ def original_citation_present?

def items_by_object(object)
# TODO- replace with index?
Catalog.chronological_item_sort( items.select{|i| i.object == object} )
::Catalog.chronological_item_sort( items.select{|i| i.object == object} )
end

# @return [Array of NomenclatureCatalog::EntryItem]
# sorted by date, then taxon name name as rendered for this item
def ordered_by_nomenclature_date
Catalog.chronological_item_sort(items)
::Catalog.chronological_item_sort(items)
end

# @param [Source] source
Expand Down
32 changes: 16 additions & 16 deletions lib/catalog/entry_item.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@

# 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.
class Catalog::EntryItem

# The focus of this entry item
# This is not an attribute of Catalog::Entry (no!)
# Entry -> taxon name
# EntryItem.object -> relationship
# EntryItem.base_object -> synonym
# The visualized element of this entry item, e.g. the subject taxon name of a taxon name relationship
attr_accessor :base_object

# The focus of this entry item
# The source of this entry item, e.g. a TaxonNameRelationship
attr_accessor :object

# Optional
# Optional, should be provided explicitly
attr_accessor :citation

# @return [Time, nil]
Expand All @@ -20,12 +16,15 @@ class Catalog::EntryItem
# See also citation_date
attr_accessor :nomenclature_date

# @return [Symbol]
# a pointer to a method in /app/helpers
attr_accessor :to_html_method

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

#
# @return [Boolean]
# See Entry#first_item?
# See Catalog::Entry#first_item?
attr_accessor :is_first

# @param [Hash] args
Expand All @@ -49,11 +48,12 @@ def base_data_attributes
}
end

# @return [Boolean]
def is_subsequent?
# object == taxon_name && !citation.try(:is_original?)
references_self && !citation.nil? && !citation.is_original?
end
# Deprecated for is_first
# # @return [Boolean]
# def is_subsequent?
# # object == taxon_name && !citation.try(:is_original?)
# references_self && !citation.nil? && !citation.is_original?
# end

def references_self?
object == base_object
Expand Down Expand Up @@ -83,7 +83,7 @@ def nomenclature_date
nil
end
end

# @return [String]
# do not update with base_class
def object_class
Expand Down
50 changes: 24 additions & 26 deletions lib/catalog/nomenclature/entry.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
# A Catalog Entry contains the metadata the nomenclatural history of a single "reference" taxon name.
# Mutiple CatalogEntries would make up a catalog.
# A Catalog::Entry that contains the nomenclatural history of a single TaxonName
# Mutiple Catalog::Entries would make up a catalog.

# EntryItems for this Entry must follow:
# EntryItems for this Entry must follow the pattern:
# * The `base_object` is always a TaxonName
# * The `object` may be a Protony, TaxonNameRelationship, or Combination
#
class Catalog::Nomenclature::Entry < Catalog::Entry

# The taxon name being referenced in this entry (think of it as the header)
# attr_accessor :reference_taxon_name

def initialize(taxon_name)
super(taxon_name)
end

# @return [Array of NomenclatureCatalog::EntryItem]
# sorted by date, then taxon name name as rendered for this item
def ordered_by_nomenclature_date
now = Time.now
items.sort{|a,b| [(a.nomenclature_date || now), a.object_class, a.base_object.cached_original_combination.to_s ] <=> [(b.nomenclature_date || now), b.object_class, b.base_object.cached_original_combination.to_s ] }
end

# @return [Array of EntryItems]
# only those entry items that reference a TaxonNameRelationship
def relationship_items
items.select{|i| i.object_class =~ /TaxonNameRelationship/}
end

# @return [Scope]
def names
@names ||= all_names
@names
end

# @param [TaxonName] taxon_name
def build
v = object.valid_taxon_name
base_names = v.historical_taxon_names
Expand Down Expand Up @@ -68,6 +46,20 @@ def build
true
end


# @return [Array of NomenclatureCatalog::EntryItem]
# sorted by date, then taxon name name as rendered for this item
def ordered_by_nomenclature_date
now = Time.now
items.sort{|a,b| [(a.nomenclature_date || now), a.object_class, a.base_object.cached_original_combination.to_s ] <=> [(b.nomenclature_date || now), b.object_class, b.base_object.cached_original_combination.to_s ] }
end

# @return [Array]
def names
@names ||= all_names
@names
end

protected

# @param [CatalogEntry] catalog_item
Expand Down Expand Up @@ -111,4 +103,10 @@ def all_protonyms
items.select{|i| i.origin == 'protonym' }
end

# @return [Array of EntryItems]
# only those entry items that reference a TaxonNameRelationship
def relationship_items
items.select{|i| i.object_class =~ /TaxonNameRelationship/}
end

end
23 changes: 2 additions & 21 deletions lib/catalog/nomenclature/entry_item.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

# Is 1:1 with a Citation
class Catalog::Nomenclature::EntryItem < ::Catalog::EntryItem
# @param [Hash] args

def initialize(object: nil, base_object: nil, citation: nil, nomenclature_date: nil, citation_date: nil)
# raise if nomenclature_date.nil? && !%w{Protonym Combination TaxonNameRelationship}.include?(object.class.to_s)
super
end

Expand All @@ -23,30 +20,14 @@ def other_name
end
end

# # @return [String]
# def origin
# case object_class
# when 'Protonym'
# 'protonym'
# when 'Hybrid'
# 'hybrid'
# when 'Combination'
# 'combination'
# when /TaxonNameRelationship/
# 'taxon_name_relationship'
# else
# 'error'
# end
# end

# @return [Boolean]
def is_valid_name?
object_class == 'Protonym' && object.is_valid?
end

def data_attributes
base_data_attributes.merge(
'history-valid-name' => is_valid_name? && is_subsequent?
'history-valid-protonym' => is_valid_name?
)
end

Expand Down
13 changes: 6 additions & 7 deletions lib/catalog/timeline.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

# Filtering attributes
#
# data-
# origin: 'Original' Filter should be on 'otu' vs. everything else
# is_subsequent, 'Current' : if multiple citations, then true if is_original OR first in order if none is_original
# A Catalog::Timeline is a catalog that merges biolgological concepts (OTUs) with their nomenclature.
#
# valid: true if object is a valid name, or object is otu and linked to valid_name ?
# Filtering intent:
# Level 1: [Nomenclature, Protonym, OTU (biology)] - mutually exclusive
# Level 2 (All): [First, Valid]
#
# Visualizing intent:
# [Origin] tag
class Catalog::Timeline < Catalog

def build
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/catalog/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
end

specify '#first_item?' do
expect(catalog_entry.first_item?(items.first)).to be_truthy
expect(catalog_entry.first_item?(catalog_entry.items.first)).to be_truthy
end

specify '#original_citation_present?' do
expect(catalog_entry.original_citation_present?).to be_truthy
end

specify '#items_by_object' do
expect(catalog_entry.items_by_object(catalog.items.first.object)).to contain_exactly(items.first)
expect(catalog_entry.items_by_object(catalog_entry.items.first.object)).to contain_exactly(catalog_entry.items.first)
end

end
Expand Down

0 comments on commit 6e50964

Please sign in to comment.