Module: Locabulary

Defined in:
lib/locabulary.rb,
lib/locabulary/item.rb,
lib/locabulary/items.rb,
lib/locabulary/schema.rb,
lib/locabulary/utility.rb,
lib/locabulary/version.rb,
lib/locabulary/services.rb,
lib/locabulary/exceptions.rb,
lib/locabulary/items/base.rb,
lib/locabulary/json_creator.rb,
lib/locabulary/hierarchy_processor.rb,
lib/locabulary/facet_wrapper_for_item.rb,
lib/locabulary/items/administrative_unit.rb,
lib/locabulary/services/item_for_service.rb,
lib/locabulary/services/all_items_for_service.rb,
lib/locabulary/services/active_items_for_service.rb,
lib/locabulary/services/active_hierarchical_roots_service.rb,
lib/locabulary/services/build_ordered_hierarchical_tree_service.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Exceptions, Item, Items Classes: FacetWrapperForItem, JsonCreator

Constant Summary collapse

Schema =

Responsible for providing a defined and clear schema for each of the locabulary items.

Since:

  • 0.1.0

Dry::Validation.Schema do
  required(:predicate_name).filled(format?: /\A[a-z_]+\Z/)
  required(:values).each do
    required(:term_label).filled(:str?)
    optional(:description).maybe(:str?)
    optional(:grouping).maybe(:str?)
    optional(:affiliation).maybe(:str?)
    optional(:default_presentation_sequence).maybe(:int?)
    required(:activated_on).filled(format?: /\A\d{4}-\d{2}-\d{2}\Z/)
    optional(:deactivated_on).maybe(format?: /\A\d{4}-\d{2}-\d{2}\Z/)
  end
end
VERSION =
'0.8.1'.freeze

Class Method Summary collapse

Class Method Details

.active_hierarchical_roots(options = {}) ⇒ Array<Locabulary::Items::Base>

Responsible for transforming the flat data for the given :predicate_name into a hierarchy.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)
  • :as_of (Date) — default: Date.today

Returns:

See Also:

  • Services

Since:

  • 0.4.0



70
71
72
# File 'lib/locabulary.rb', line 70

def self.active_hierarchical_roots(options = {})
  Services.call(:active_hierarchical_roots, options)
end

.active_items_for(options = {}) ⇒ Array<Locabulary::Items::Base>

Responsible for extracting a non-hierarchical sorted array of active Locabulary::Items::Base objects for the given predicate_name.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)
  • :as_of (Date) — default: Date.today

Returns:

See Also:

  • Services

Since:

  • 0.1.0



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

def self.active_items_for(options = {})
  Services.call(:active_items_for, options)
end

.active_label_for_uri(options = {}) ⇒ String

For the given :predicate_name and :term_uri return a best fitting human readable label.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)
  • :term_uri (String)
  • :as_of (String) — default: Date.today

Returns:

  • (String)

    a label or URI

See Also:

Since:

  • 0.1.0



105
106
107
108
109
110
# File 'lib/locabulary.rb', line 105

def self.active_label_for_uri(options = {})
  term_uri = options.fetch(:term_uri)
  object = active_items_for(options).detect { |obj| obj.term_uri == term_uri }
  return object.term_label if object
  term_uri
end

.active_labels_for(options = {}) ⇒ Array<String>

Return an Array of term labels for the given :predicate_name

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)
  • :as_of (String) — default: Date.today

Returns:

  • (Array<String>)

    an array of Locabuarly::Items::Base#term_label

See Also:

Since:

  • 0.1.0



123
124
125
# File 'lib/locabulary.rb', line 123

def self.active_labels_for(options = {})
  active_items_for(options).map(&:term_label)
end

.all_items_for(options = {}) ⇒ Array<Locabulary::Items::Base>

Responsible for extracting a non-hierarchical sorted array of Locabulary::Items::Base objects for the given predicate_name.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)

Returns:

See Also:

  • Services

Since:

  • 0.7.0



54
55
56
# File 'lib/locabulary.rb', line 54

def self.all_items_for(options = {})
  Services.call(:all_items_for, options)
end

.build_ordered_hierarchical_tree(options = {}) ⇒ Array<FacetWrapperForItem>

Responsible for building a hierarchical tree from faceted items, and ordering the nodes as per the presentation sequence for the associated predicate_name.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)
  • :faceted_items (Array<#hits, #value>)
  • :faceted_item_hierarchy_delimiter (String)

Returns:

See Also:

  • Services

Since:

  • 0.5.0



25
26
27
# File 'lib/locabulary.rb', line 25

def self.build_ordered_hierarchical_tree(options = {})
  Services.call(:build_ordered_hierarchical_tree, options)
end

.item_for(options = {}) ⇒ Locabulary::Items::Base

For the given :predicate_name and :term_label find an item. We prefer to find an active item, but will settle for a non-active item.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :predicate_name (String)
  • :term_label (String)
  • :as_of (Date) — default: Date.today

Returns:

Raises:

See Also:

  • Services

Since:

  • 0.5.0



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

def self.item_for(options = {})
  Services.call(:item_for, options)
end