lib/locabulary.rb in locabulary-0.6.1 vs lib/locabulary.rb in locabulary-0.6.2
- old
+ new
@@ -1,12 +1,15 @@
-require 'date'
-require 'json'
-require 'locabulary/exceptions'
-require 'locabulary/item'
require 'locabulary/services'
# @since 0.1.0
+# @api public
+#
+# Locabulary is structured to expose public interface methods in the base module (e.g. `Locabulary`).
+# Other things to consider are the Locabulary::Items::Base object as it defines the returned data structure
+# for the public Locabulary methods.
+#
+# @see Locabury::Items::Base
module Locabulary
# @api public
# @since 0.5.0
#
# Responsible for building a hierarchical tree from faceted items, and ordering the nodes as per the presentation sequence for the
@@ -46,10 +49,11 @@
#
# @param [Hash] options
# @option options [String] :predicate_name
# @option options [Date] :as_of (Date.today)
# @return [Array<Locabulary::Items::Base>] - the root nodes
+ #
# @see Locabulary::Services
def self.active_hierarchical_roots(options = {})
Services.call(:active_hierarchical_roots, options)
end
@@ -63,25 +67,19 @@
# @option options [String] :predicate_name
# @option options [String] :term_label
# @option options [Date] :as_of (Date.today)
# @raise [Locabulary::Exceptions::ItemNotFoundError] if unable to find label for predicate_name
# @return [Locabulary::Items::Base]
+ #
+ # @see Locabulary::Services
def self.item_for(options = {})
- predicate_name = options.fetch(:predicate_name)
- term_label = options.fetch(:term_label)
- as_of = options.fetch(:as_of) { Date.today }
- item = nil
- Utility.with_extraction_for(predicate_name) do |data|
- next unless data.fetch('term_label') == term_label
- item = Item.build(data.merge('predicate_name' => predicate_name))
- break if Utility.data_is_active?(data, as_of)
- end
- return item unless item.nil?
- raise Locabulary::Exceptions::ItemNotFoundError.new(predicate_name, term_label)
+ Services.call(:item_for, options)
end
# @api public
# @since 0.1.0
+ #
+ # For the given :predicate_name and :term_uri return a best fitting human readable label.
#
# @param [Hash] options
# @option options [String] :predicate_name
# @option options [String] :term_uri
# @option options [String] :as_of (Date.today)