locabulary 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/rspec_isolated +5 -0
- data/lib/locabulary/commands/active_hierarchical_roots_command.rb +1 -1
- data/lib/locabulary/commands/active_items_for_command.rb +1 -2
- data/lib/locabulary/commands/build_ordered_hierarchical_tree_command.rb +15 -6
- data/lib/locabulary/facet_wrapper_for_item.rb +4 -3
- data/lib/locabulary/item.rb +15 -3
- data/lib/locabulary/version.rb +1 -1
- data/lib/locabulary.rb +0 -6
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6860e6b46a871aa5f6fa44d61e4a71549fe997d
|
4
|
+
data.tar.gz: 8e45a3991ac5fac5b35944094db338ac8d484c0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0934da270aa054be0eae9d1dea2db1739d1fdabc79142f6845efe944b0b332816330b0ab74712c4c165f1526747d1f82d563e4e43d0734d0191ca6d0fea4cd8
|
7
|
+
data.tar.gz: 4e137b994cc4d406e2a5787ac565e20eeca0b2aa7325707c2bf7d536a5e4543fe353fbdc05f19fcd04eb20dd2575b108dbc8e52bfcb7ce1838448ac7777fc65e
|
data/README.md
CHANGED
data/bin/rspec_isolated
ADDED
@@ -13,9 +13,10 @@ module Locabulary
|
|
13
13
|
# @since 0.5.0
|
14
14
|
#
|
15
15
|
# @param options [Hash]
|
16
|
-
# @option
|
17
|
-
# @option
|
18
|
-
# @option
|
16
|
+
# @option options [String] :predicate_name
|
17
|
+
# @option options [Array<#hits, #value>] :faceted_items
|
18
|
+
# @option options [String] :faceted_item_hierarchy_delimiter
|
19
|
+
# For any given item in faceted_items how is the hierarchy encoded in the :value?
|
19
20
|
#
|
20
21
|
# @return [Array<FacetWrapperForItem>]
|
21
22
|
def self.call(options = {})
|
@@ -26,7 +27,7 @@ module Locabulary
|
|
26
27
|
@predicate_name = options.fetch(:predicate_name)
|
27
28
|
@faceted_items = options.fetch(:faceted_items)
|
28
29
|
@faceted_item_hierarchy_delimiter = options.fetch(:faceted_item_hierarchy_delimiter)
|
29
|
-
@
|
30
|
+
@locabulary_item_class = Item.class_to_instantiate(predicate_name: predicate_name)
|
30
31
|
end
|
31
32
|
|
32
33
|
def call
|
@@ -45,7 +46,7 @@ module Locabulary
|
|
45
46
|
|
46
47
|
private
|
47
48
|
|
48
|
-
attr_reader :
|
49
|
+
attr_reader :locabulary_item_class, :predicate_name, :faceted_items, :faceted_item_hierarchy_delimiter
|
49
50
|
|
50
51
|
def associate_parents_and_childrens_for(hierarchy_graph_keys, items)
|
51
52
|
items.each do |item|
|
@@ -58,7 +59,7 @@ module Locabulary
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def build_item(faceted_node)
|
61
|
-
term_label = faceted_node.value
|
62
|
+
term_label = convert_faceted_node_value_to_term_label(faceted_node.value)
|
62
63
|
locabulary_item = find_locabulary_item(predicate_name: predicate_name, term_label: term_label)
|
63
64
|
if locabulary_item
|
64
65
|
FacetWrapperForItem.build_for_faceted_node_and_locabulary_item(faceted_node: faceted_node, locabulary_item: locabulary_item)
|
@@ -75,6 +76,14 @@ module Locabulary
|
|
75
76
|
# that we want to consider a developer notification but not abort the whole process.
|
76
77
|
nil
|
77
78
|
end
|
79
|
+
|
80
|
+
# Responsible for converting the hierarchy delimiter of the facet item to the hierarchy delimiter of the Locabulary::Item.
|
81
|
+
def convert_faceted_node_value_to_term_label(value)
|
82
|
+
value.gsub(
|
83
|
+
/(?<!#{faceted_item_hierarchy_delimiter})#{faceted_item_hierarchy_delimiter}(?!#{faceted_item_hierarchy_delimiter})/,
|
84
|
+
locabulary_item_class.hierarchy_delimiter
|
85
|
+
)
|
86
|
+
end
|
78
87
|
end
|
79
88
|
end
|
80
89
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'delegate'
|
3
|
+
require 'locabulary/item'
|
3
4
|
|
4
5
|
module Locabulary
|
5
6
|
# A wrapper for a Locabulary::Items::Base that includes information from
|
@@ -22,7 +23,7 @@ module Locabulary
|
|
22
23
|
predicate_name = options.fetch(:predicate_name)
|
23
24
|
faceted_node = options.fetch(:faceted_node)
|
24
25
|
term_label = options.fetch(:term_label)
|
25
|
-
locabulary_item =
|
26
|
+
locabulary_item = Item.build(predicate_name: predicate_name, term_label: term_label, default_presentation_sequence: nil)
|
26
27
|
new(faceted_node: faceted_node, locabulary_item: locabulary_item)
|
27
28
|
end
|
28
29
|
|
@@ -34,7 +35,7 @@ module Locabulary
|
|
34
35
|
# @see Locabulary::FacetedHierarchicalTreeSorter
|
35
36
|
# @param options [Hash]
|
36
37
|
# @option predicate_name [String]
|
37
|
-
# @option faceted_node [#
|
38
|
+
# @option faceted_node [#value, #hits]
|
38
39
|
# @option term_label [String]
|
39
40
|
# @return Locabulary::FacetWrapperForItem
|
40
41
|
def self.build_for_faceted_node_and_locabulary_item(options = {})
|
@@ -53,6 +54,6 @@ module Locabulary
|
|
53
54
|
attr_reader :__faceted_node__, :__locabulary_item__
|
54
55
|
|
55
56
|
extend Forwardable
|
56
|
-
def_delegators :__faceted_node__, :
|
57
|
+
def_delegators :__faceted_node__, :value, :hits
|
57
58
|
end
|
58
59
|
end
|
data/lib/locabulary/item.rb
CHANGED
@@ -15,11 +15,12 @@ module Locabulary
|
|
15
15
|
# @see Locabulary::Items
|
16
16
|
def self.build(attributes = {})
|
17
17
|
predicate_name = attributes.fetch(:predicate_name) { attributes.fetch('predicate_name') }
|
18
|
-
|
18
|
+
class_to_instantiate(predicate_name: predicate_name).new(attributes)
|
19
19
|
end
|
20
20
|
|
21
21
|
# @api public
|
22
22
|
# @since 0.2.1
|
23
|
+
# @deprecated 0.6.0 Prefer instead class_to_instantiate
|
23
24
|
#
|
24
25
|
# Responsible for finding the appropriate Factory method for building a Locabulary::Item
|
25
26
|
#
|
@@ -27,14 +28,25 @@ module Locabulary
|
|
27
28
|
# @option predicate_name [String] Used for lookup of the correct Locabulary::Item type
|
28
29
|
# @return [#call] A builder method (`.new` for the given constant)
|
29
30
|
def self.builder_for(options = {})
|
31
|
+
class_to_instantiate(options).method(:new)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @api public
|
35
|
+
# @since 0.5.1
|
36
|
+
#
|
37
|
+
# Responsible for finding the appropriate class that will be instantiated
|
38
|
+
#
|
39
|
+
# @param options [Hash]
|
40
|
+
# @option options [String] :predicate_name Used for lookup of the correct Locabulary::Item type
|
41
|
+
# @return [Locabulary::Items::Base]
|
42
|
+
def self.class_to_instantiate(options = {})
|
30
43
|
predicate_name = options.fetch(:predicate_name)
|
31
44
|
possible_class_name_for_predicate_name = predicate_name.singularize.classify
|
32
|
-
|
45
|
+
begin
|
33
46
|
Items.const_get(possible_class_name_for_predicate_name)
|
34
47
|
rescue NameError
|
35
48
|
Items::Base
|
36
49
|
end
|
37
|
-
klass.method(:new)
|
38
50
|
end
|
39
51
|
end
|
40
52
|
end
|
data/lib/locabulary/version.rb
CHANGED
data/lib/locabulary.rb
CHANGED
@@ -108,10 +108,4 @@ module Locabulary
|
|
108
108
|
def self.active_labels_for(options = {})
|
109
109
|
active_items_for(options).map(&:term_label)
|
110
110
|
end
|
111
|
-
|
112
|
-
# @api private
|
113
|
-
def self.reset_active_cache!
|
114
|
-
Commands::ActiveItemsForCommand.reset_cache!
|
115
|
-
Commands::ActiveHierarchicalRootsCommand.reset_cache!
|
116
|
-
end
|
117
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locabulary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- LICENSE
|
241
241
|
- README.md
|
242
242
|
- Rakefile
|
243
|
+
- bin/rspec_isolated
|
243
244
|
- config/client_secrets.example.yml
|
244
245
|
- data/administrative_units.json
|
245
246
|
- data/affiliation.json
|