lib/locabulary/items/administrative_unit.rb in locabulary-0.3.1 vs lib/locabulary/items/administrative_unit.rb in locabulary-0.5.0

- old
+ new

@@ -1,5 +1,6 @@ +# encoding: UTF-8 require 'locabulary/exceptions' require 'locabulary/items/base' module Locabulary module Items @@ -25,47 +26,18 @@ attr_writer :homepage, :classification, :grouping, :affiliation public - def initialize(*args) - super - @children = [] - end - - def children - @children.sort - end - - def add_child(*input) - @children += input - end - - HIERARCHY_SEPARATOR = '::'.freeze - def slugs - term_label.split(HIERARCHY_SEPARATOR) - end - - def parent_slugs - slugs[0..-2] - end - - def parent_term_label - parent_slugs.join(HIERARCHY_SEPARATOR) - end - - def root_slug - slugs[0] - end - - def selectable? - children.count == 0 - end - + NON_DEPARTMENTAL_SLUG = "Non-Departmental".freeze + # NOTE: The whitespace characters are "thin spaces", U+200A + HUMAN_FRIENDLY_HIERARCHY_DELIMITER = ' — '.freeze def selectable_label - slugs[1..-1].join(HIERARCHY_SEPARATOR) + if slugs[-1] == NON_DEPARTMENTAL_SLUG + slugs[-2..-1].join(HUMAN_FRIENDLY_HIERARCHY_DELIMITER) + else + slugs[-1] + end end - - alias selectable_id id end end end