Skip to content
Jim Posen edited this page Jun 18, 2013 · 2 revisions

The taxonomy is the hierarchical tree of sections of the Chronicle organization. The top level sections are News, Sports, Opinion, Recess, and Towerview. The taxonomy is a tree structure stored in the site configuration. It can be arbitrarily deep but is preferably wide rather than deep. Each article has a section which must be valid under the taxonomy structure.

Taxonomy Class

The Taxonomy class should be used to operate with sections. A section is defined by it's path in the taxonomy tree. To create a Taxonomy instance, you may construct it using an array of path elements or using the string serialization (see "String representation" below). The path elements are case insensitive as the canonical capitalization of a section is stored in the configuration.

Taxonomy.new(['News', 'University'])
Taxonomy.new('/news/university/')

A Taxonomy may also be instantiated using bracket notation.

Taxonomy['News', 'University']

Attempting to construct a Taxonomy for a section that is not in the configuration will result in an error.

Taxonomy['Fake', 'Section']  # => Taxonomy::InvalidTaxonomyError

String representation

Taxonomy objects can be serialized to strings using the Taxonomy#to_s method and reconstructed from strings using the regular constructor. The format is the section path lower cased and delimited by slashes. The string must begin and end with a slash as well. Note that a section's serialization will always be a prefix of its children's string representations.

Taxonomy['News', 'University', 'DSG'].to_s  # => '/news/university/dsg/'

If a persisted model has a section property, the database should store the section as a string. This can be achieved with the following code for an ActiveModel.

class ModelWithTaxonomy < ActiveRecord::Base
  attr_accessible :section
  serialize :section, Taxonomy::Serializer.new

  ...
end

Root Taxonomy

The root Taxonomy is the ancestor of all sections. The root has no path elements. The Taxonomy#root? method can be used to test if a Taxonomy instance is the root. It can be created by passed nil or no constructor arguments to Taxonomy. The string representation of the root taxonomy is /.

Taxonomy.new.root?  # true

Taxonomy Configuration

The taxonomy tree is stored in YAML format at config/taxonomy.yml. This file should not be parsed directly, except in the Taxonomy class. Changes to the taxonomy tree must be approved by the editorial staff.

Clone this wiki locally