Module: Autoselect::Levels::ColResolvedName

Includes:
ColSourceMark
Included in:
Otu::Levels::ColValidName, TaxonName::Levels::ColValidName
Defined in:
lib/autoselect/levels/col_resolved_name.rb

Constant Summary

Constants included from ColSourceMark

Autoselect::Levels::ColSourceMark::COL_ICON, Autoselect::Levels::ColSourceMark::TW_ICON

Instance Method Summary collapse

Methods included from ColSourceMark

#col_existing_record?, #col_source_icon, #col_source_tag

Instance Method Details

#col_resolved_badges(record) ⇒ Array<Array(String, Symbol)> (private)

Returns [text, feedback type] pairs for everything after the source mark, in display order.

Returns:

  • (Array<Array(String, Symbol)>) —

    [text, feedback type] pairs for everything after the source mark, in display order



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/autoselect/levels/col_resolved_name.rb', line 57

def col_resolved_badges(record)
  extension = record._col_extension
  badges = []

  status = extension[:col_status].presence
  if status && !status.to_s.casecmp?('accepted')
    badges << [status, :warning]
  end

  if (rank = extension[:col_rank].presence)
    badges << [rank, :light]
  end

  if (acronym = extension[:col_code_acronym])
    badges << [acronym, :light]
  end

  if (synonym = resolved_synonym(record))
    badges << [%(valid name for "#{synonym}"), :warning]
    if record._col_extension[:resolved_ambiguous]
      badges << ['ambiguous synonym', :warning]
    end
  end

  badges
end

#record_info(record) ⇒ Array<String>

Returns source tag ("TW"/"CoL"), then any non-accepted status, the rank, the code (see ColCodeBadge), and a "valid name for X" note when CoL followed synonymy (then "ambiguous synonym" when X is one). Falls back to the ancestor's info for anything without CoL provenance.

Returns:

  • (Array<String>) —

    source tag ("TW"/"CoL"), then any non-accepted status, the rank, the code (see ColCodeBadge), and a "valid name for X" note when CoL followed synonymy (then "ambiguous synonym" when X is one). Falls back to the ancestor's info for anything without CoL provenance.



35
36
37
38
39
# File 'lib/autoselect/levels/col_resolved_name.rb', line 35

def record_info(record)
  return super if resolved_from(record).nil?

  [col_source_tag(record), *col_resolved_badges(record).map(&:first)]
end

#record_info_html(record) ⇒ String

Returns same as #record_info, but the source tag is an inline brand-mark icon in front of styled feedback badges for the rest.

Returns:

  • (String) —

    same as #record_info, but the source tag is an inline brand-mark icon in front of styled feedback badges for the rest.



43
44
45
46
47
48
49
50
51
# File 'lib/autoselect/levels/col_resolved_name.rb', line 43

def record_info_html(record)
  return super if resolved_from(record).nil?

  h = ApplicationController.helpers
  badges = col_resolved_badges(record).map do |text, type|
    h.feedback_badge_tag(text, type)
  end
  col_source_icon(record) + badges.join(' ')
end

#resolved_from(record) ⇒ Object (private)

The raw text CoL resolved to produce this record. nil for anything without CoL provenance.



93
94
95
96
97
98
# File 'lib/autoselect/levels/col_resolved_name.rb', line 93

def resolved_from(record)
  if record.respond_to?(:_col_extension)
    return record._col_extension[:resolved_from]
  end
  nil
end

#resolved_synonym(record) ⇒ Object (private)

The synonym CoL matched and followed to this record's valid name. nil when CoL didn't follow synonymy, or for anything without CoL provenance.



86
87
88
89
# File 'lib/autoselect/levels/col_resolved_name.rb', line 86

def resolved_synonym(record)
  return nil if resolved_from(record).nil?
  record._col_extension[:resolved_synonym].presence
end