locabulary 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/data/administrative_units.json +27 -2
- data/data/affiliation.json +5 -1
- data/lib/locabulary/items/administrative_unit.rb +18 -0
- data/lib/locabulary/items/base.rb +3 -7
- data/lib/locabulary/json_creator.rb +32 -27
- data/lib/locabulary/services/{active_hierarchical_roots_command.rb → active_hierarchical_roots_service.rb} +2 -2
- data/lib/locabulary/services/{active_items_for_command.rb → active_items_for_service.rb} +2 -2
- data/lib/locabulary/services/{build_ordered_hierarchical_tree_command.rb → build_ordered_hierarchical_tree_service.rb} +2 -2
- data/lib/locabulary/services/item_for_service.rb +42 -0
- data/lib/locabulary/services.rb +7 -4
- data/lib/locabulary/utility.rb +29 -0
- data/lib/locabulary/version.rb +1 -1
- data/lib/locabulary.rb +13 -15
- data/locabulary.gemspec +8 -2
- metadata +84 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 893a00c3a81700792d4558e04196c122fdc42332
|
4
|
+
data.tar.gz: 63970fd7b77f9c02beb746372ed11989e921e391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e49182de88472548233ec41409b0261b7ed8aea868cbb3f161d2c35a1e05df07235172a085f94b37bc5869fec097941bd94bee18e44a140ac5fdc0432570feb
|
7
|
+
data.tar.gz: c5d31f75202844612f7d91c3afaa753d5473923b997c1a73419db4cfd9f0078f915ac8d6ffe650b1ddce6081aa0d53a8a28bf9704b95a49f2357a4a5dbb9e581
|
data/README.md
CHANGED
@@ -11,8 +11,24 @@ An extraction of limited localized vocabulary for Sipity and CurateND.
|
|
11
11
|
This controlled vocabulary has a limited shelf-life as we explore other more
|
12
12
|
robust options.
|
13
13
|
|
14
|
+
## Getting Started
|
15
|
+
|
16
|
+
See the [Locublary module in lib/locabulary](/lib/locabulary.rb) for the public methods of this gem.
|
17
|
+
|
14
18
|
## Testing
|
15
19
|
|
16
20
|
The full test suite is run via `bundle exec rake`.
|
17
21
|
|
18
22
|
If you are interested in running each file in isolation - a good thing for unit tests - use `./bin/rspec_isolated`.
|
23
|
+
|
24
|
+
## Updating Data Files
|
25
|
+
|
26
|
+
The "administrative_units" data is maintained in a Google Spreadsheet. To synchronize the JSON data:
|
27
|
+
|
28
|
+
1. Ensure that you have a copy of the `config/client_secret.yml` from the staging secrets
|
29
|
+
2. Make sure you have a clean working tree (eg. `git status` shows no changes)
|
30
|
+
3. Run `bundle exec ./script/update_data_files.sh` script following its instructions
|
31
|
+
4. Review changes to the `data/administrative_units.json` file (eg. `git diff`)
|
32
|
+
5. Commit changes
|
33
|
+
|
34
|
+
Once committed and pushed upstream, to see the changes will require a deploy of the applications.
|
@@ -5,9 +5,9 @@
|
|
5
5
|
"predicate_name": "administrative_units",
|
6
6
|
"term_label": "University of Notre Dame",
|
7
7
|
"classification": "University",
|
8
|
+
"default_presentation_sequence": 1,
|
8
9
|
"homepage": "http://www.nd.edu/",
|
9
|
-
"activated_on": "2015-07-22"
|
10
|
-
"default_presentation_sequence": 1
|
10
|
+
"activated_on": "2015-07-22"
|
11
11
|
},
|
12
12
|
{
|
13
13
|
"predicate_name": "administrative_units",
|
@@ -572,6 +572,14 @@
|
|
572
572
|
"homepage": "http://business.nd.edu/Center_for_the_Study_of_Financial_Regulation/",
|
573
573
|
"activated_on": "2015-07-22"
|
574
574
|
},
|
575
|
+
{
|
576
|
+
"predicate_name": "administrative_units",
|
577
|
+
"term_label": "University of Notre Dame::Centers and Institutes::Center for the Study of Languages and Cultures",
|
578
|
+
"classification": "CenterOrInstitute",
|
579
|
+
"affiliation": "University of Notre Dame::College of Arts and Letters",
|
580
|
+
"homepage": "http://cslc.nd.edu/",
|
581
|
+
"activated_on": "2015-07-22"
|
582
|
+
},
|
575
583
|
{
|
576
584
|
"predicate_name": "administrative_units",
|
577
585
|
"term_label": "University of Notre Dame::Centers and Institutes::Center for the Study of Religion and Society",
|
@@ -704,6 +712,14 @@
|
|
704
712
|
"homepage": "http://latinostudies.nd.edu/",
|
705
713
|
"activated_on": "2015-07-22"
|
706
714
|
},
|
715
|
+
{
|
716
|
+
"predicate_name": "administrative_units",
|
717
|
+
"term_label": "University of Notre Dame::Centers and Institutes::Institute for Scholarship in the Liberal Arts",
|
718
|
+
"classification": "CenterOrInstitute",
|
719
|
+
"affiliation": "University of Notre Dame::College of Arts and Letters",
|
720
|
+
"homepage": "https://isla.nd.edu/",
|
721
|
+
"activated_on": "2015-07-22"
|
722
|
+
},
|
707
723
|
{
|
708
724
|
"predicate_name": "administrative_units",
|
709
725
|
"term_label": "University of Notre Dame::Centers and Institutes::Institute for Theoretical Sciences",
|
@@ -889,10 +905,19 @@
|
|
889
905
|
"homepage": "http://wireless.nd.edu/",
|
890
906
|
"activated_on": "2015-07-22"
|
891
907
|
},
|
908
|
+
{
|
909
|
+
"predicate_name": "administrative_units",
|
910
|
+
"term_label": "University of Notre Dame::University of Notre Dame Press",
|
911
|
+
"classification": "CampusOffice",
|
912
|
+
"default_presentation_sequence": 12,
|
913
|
+
"homepage": "http://undpress.nd.edu/",
|
914
|
+
"activated_on": "2015-07-22"
|
915
|
+
},
|
892
916
|
{
|
893
917
|
"predicate_name": "administrative_units",
|
894
918
|
"term_label": "Catholic Organizations",
|
895
919
|
"classification": "OrganizationalGroup",
|
920
|
+
"default_presentation_sequence": 13,
|
896
921
|
"activated_on": "2015-07-22"
|
897
922
|
},
|
898
923
|
{
|
data/data/affiliation.json
CHANGED
@@ -6,10 +6,14 @@
|
|
6
6
|
},{
|
7
7
|
"term_label": "Staff research and publications",
|
8
8
|
"activated_on": "2015-01-01"
|
9
|
+
},{
|
10
|
+
"term_label": "Postdoctoral research and publications",
|
11
|
+
"activated_on": "2016-09-15"
|
9
12
|
},{
|
10
13
|
"term_label": "Graduate research and publications",
|
11
14
|
"activated_on": "2015-01-01"
|
12
|
-
}
|
15
|
+
}
|
16
|
+
,{
|
13
17
|
"term_label": "Undergraduate research and publications",
|
14
18
|
"activated_on": "2015-01-01"
|
15
19
|
},{
|
@@ -18,8 +18,26 @@ module Locabulary
|
|
18
18
|
# [String] What is the URL of the homepage. Please note the term_uri is reserved for something that is more resolvable by machines.
|
19
19
|
# And while the homepage may look resolvable, it is not as meaningful for longterm preservation.
|
20
20
|
attr_reader :homepage
|
21
|
+
|
22
|
+
# [String, nil] The type of administrative unit in the hierarchy (e.g. College, Department, University, etc.)
|
21
23
|
attr_reader :classification
|
24
|
+
|
25
|
+
# [String, nil] A larger concept that ties units together; "The Humanities" is a grouping for the following:
|
26
|
+
# * "University of Notre Dame::College of Arts and Letters::Africana Studies"
|
27
|
+
# * "University of Notre Dame::College of Arts and Letters::American Studies"
|
22
28
|
attr_reader :grouping
|
29
|
+
|
30
|
+
# [String, nil] For centers and institutes, there is often an affiliation to another administrative unit.
|
31
|
+
# @example
|
32
|
+
#
|
33
|
+
# {
|
34
|
+
# "predicate_name": "administrative_units",
|
35
|
+
# "term_label": "University of Notre Dame::Centers and Institutes::Center for Accounting Research and Education (CARE)",
|
36
|
+
# "classification": "CenterOrInstitute",
|
37
|
+
# "affiliation": "University of Notre Dame::Mendoza College of Business",
|
38
|
+
# "homepage": "http://www3.nd.edu/~carecob/",
|
39
|
+
# "activated_on": "2015-07-22"
|
40
|
+
# }
|
23
41
|
attr_reader :affiliation
|
24
42
|
|
25
43
|
private
|
@@ -7,7 +7,7 @@ module Locabulary
|
|
7
7
|
extend Dry::Configurable
|
8
8
|
|
9
9
|
setting :attribute_names, [
|
10
|
-
:predicate_name, :term_label, :term_uri, :deposit_label, :description, :
|
10
|
+
:predicate_name, :term_label, :term_uri, :deposit_label, :description, :default_presentation_sequence,
|
11
11
|
:activated_on, :deactivated_on
|
12
12
|
].freeze
|
13
13
|
|
@@ -42,14 +42,10 @@ module Locabulary
|
|
42
42
|
attr_reader :default_presentation_sequence
|
43
43
|
|
44
44
|
# @deprecated
|
45
|
+
# The label to be used when depositing; This is deprecated in favor of mapping functions.
|
46
|
+
# Those mapping functions are in part described in Locabuarly (faceted_item_hierarchy_delimiter).
|
45
47
|
attr_reader :deposit_label
|
46
48
|
|
47
|
-
# @deprecated
|
48
|
-
attr_reader :grouping
|
49
|
-
|
50
|
-
# @deprecated
|
51
|
-
attr_reader :affiliation
|
52
|
-
|
53
49
|
def initialize(attributes = {})
|
54
50
|
attribute_names.each do |key|
|
55
51
|
value = attributes[key] || attributes[key.to_s]
|
@@ -59,46 +59,51 @@ module Locabulary
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# :nocov:
|
62
|
+
# Responsible for building credentials from code
|
63
|
+
module GoogleAccessTokenFetcher
|
64
|
+
OOB_URI = "urn:ietf:wg:oauth:2.0:oob".freeze
|
65
|
+
READ_ONLY_SCOPE = "https://www.googleapis.com/auth/drive.readonly".freeze
|
66
|
+
def self.call
|
67
|
+
# This looks a bit funny in that we can cache the tokens that are returned. However I don't want to do that.
|
68
|
+
# So instead, I'm adding a symbol that should barf if the underlying interface changes.
|
69
|
+
token_store = :token_store
|
70
|
+
|
71
|
+
client_id = Google::Auth::ClientId.new(client_secrets.fetch('client_id'), client_secrets.fetch('client_secret'))
|
72
|
+
authorizer = Google::Auth::UserAuthorizer.new(client_id, READ_ONLY_SCOPE, token_store)
|
73
|
+
authorization_url = authorizer.get_authorization_url(base_url: OOB_URI)
|
74
|
+
puts "\n Open the following URL, login with your credentials and get the authorization code \n\n #{authorization_url}\n\n"
|
75
|
+
authorization_code = ask('Authorization Code: ')
|
76
|
+
authorizer.get_credentials_from_code(base_url: OOB_URI, code: authorization_code)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.client_secrets
|
80
|
+
@secrets ||= YAML.load(File.open(File.join(secrets_path)))
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.secrets_path
|
84
|
+
if File.exist? File.join(File.dirname(__FILE__), '../../config/client_secrets.yml')
|
85
|
+
File.join(File.dirname(__FILE__), '../../config/client_secrets.yml')
|
86
|
+
else
|
87
|
+
File.join(File.dirname(__FILE__), '../../config/client_secrets.example.yml')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
62
92
|
# Responsible for interacting with Google Sheets and retrieiving relevant information
|
63
93
|
class GoogleSpreadsheet
|
64
94
|
attr_reader :access_token, :document_key, :session
|
65
95
|
|
66
96
|
private :session
|
67
97
|
|
68
|
-
def initialize(document_key)
|
98
|
+
def initialize(document_key, access_token_fetcher = GoogleAccessTokenFetcher)
|
69
99
|
@document_key = document_key
|
70
|
-
|
100
|
+
@access_token = access_token_fetcher.call
|
71
101
|
@session = GoogleDrive.login_with_oauth(access_token)
|
72
102
|
end
|
73
103
|
|
74
|
-
def configure_oauth!
|
75
|
-
client = Google::APIClient.new
|
76
|
-
auth = client.authorization
|
77
|
-
auth.client_id = client_secrets.fetch('client_id')
|
78
|
-
auth.client_secret = client_secrets.fetch('client_secret')
|
79
|
-
auth.scope = ["https://www.googleapis.com/auth/drive.readonly"]
|
80
|
-
auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
81
|
-
puts "\n Open the following URL, login with your credentials and get the authorization code \n\n #{auth.authorization_uri}\n\n"
|
82
|
-
auth.code = ask('Authorization Code: ')
|
83
|
-
auth.fetch_access_token!
|
84
|
-
@access_token = auth.access_token
|
85
|
-
end
|
86
|
-
|
87
104
|
def all_rows
|
88
105
|
session.spreadsheet_by_key(document_key).worksheets[0].rows
|
89
106
|
end
|
90
|
-
|
91
|
-
def client_secrets
|
92
|
-
@secrets ||= YAML.load(File.open(File.join(secrets_path)))
|
93
|
-
end
|
94
|
-
|
95
|
-
def secrets_path
|
96
|
-
if File.exist? File.join(File.dirname(__FILE__), '../../config/client_secrets.yml')
|
97
|
-
File.join(File.dirname(__FILE__), '../../config/client_secrets.yml')
|
98
|
-
else
|
99
|
-
File.join(File.dirname(__FILE__), '../../config/client_secrets.example.yml')
|
100
|
-
end
|
101
|
-
end
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
@@ -11,7 +11,7 @@ module Locabulary
|
|
11
11
|
#
|
12
12
|
# Responsible for transforming the flat data for the given :predicate_name
|
13
13
|
# into a hierarchy.
|
14
|
-
class
|
14
|
+
class ActiveHierarchicalRootsService
|
15
15
|
def self.cache
|
16
16
|
@cache ||= {}
|
17
17
|
end
|
@@ -72,6 +72,6 @@ module Locabulary
|
|
72
72
|
Utility
|
73
73
|
end
|
74
74
|
end
|
75
|
-
private_constant :
|
75
|
+
private_constant :ActiveHierarchicalRootsService
|
76
76
|
end
|
77
77
|
end
|
@@ -10,7 +10,7 @@ module Locabulary
|
|
10
10
|
# Responsible for extracting a non-hierarchical sorted array of Locabulary::Item for the given predicate_name
|
11
11
|
#
|
12
12
|
# @see Locabulary::Item
|
13
|
-
class
|
13
|
+
class ActiveItemsForService
|
14
14
|
def self.cache
|
15
15
|
@cache ||= {}
|
16
16
|
end
|
@@ -58,6 +58,6 @@ module Locabulary
|
|
58
58
|
|
59
59
|
attr_reader :predicate_name, :as_of, :builder
|
60
60
|
end
|
61
|
-
private_constant :
|
61
|
+
private_constant :ActiveItemsForService
|
62
62
|
end
|
63
63
|
end
|
@@ -12,7 +12,7 @@ module Locabulary
|
|
12
12
|
#
|
13
13
|
# Responsible for building a hierarchical tree from faceted items, and ordering the nodes as per the presentation sequence for the
|
14
14
|
# associated predicate_name.
|
15
|
-
class
|
15
|
+
class BuildOrderedHierarchicalTreeService
|
16
16
|
# @api private
|
17
17
|
# @since 0.5.0
|
18
18
|
#
|
@@ -72,6 +72,6 @@ module Locabulary
|
|
72
72
|
value.split(faceted_item_hierarchy_delimiter).join(locabulary_item_class.hierarchy_delimiter)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
private_constant :
|
75
|
+
private_constant :BuildOrderedHierarchicalTreeService
|
76
76
|
end
|
77
77
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'locabulary/exceptions'
|
3
|
+
require 'locabulary/utility'
|
4
|
+
require 'locabulary/item'
|
5
|
+
|
6
|
+
module Locabulary
|
7
|
+
# :nodoc:
|
8
|
+
module Services
|
9
|
+
# @api private
|
10
|
+
class ItemForService
|
11
|
+
def self.call(options = {})
|
12
|
+
new(options).call
|
13
|
+
end
|
14
|
+
|
15
|
+
private_class_method :new
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
@predicate_name = options.fetch(:predicate_name)
|
19
|
+
@term_label = options.fetch(:term_label)
|
20
|
+
@as_of = options.fetch(:as_of) { Date.today }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :predicate_name, :term_label, :as_of
|
26
|
+
|
27
|
+
public
|
28
|
+
|
29
|
+
def call
|
30
|
+
item = nil
|
31
|
+
Utility.with_extraction_for(predicate_name) do |data|
|
32
|
+
next unless data.fetch('term_label') == term_label
|
33
|
+
item = Item.build(data.merge('predicate_name' => predicate_name))
|
34
|
+
break if Utility.data_is_active?(data, as_of)
|
35
|
+
end
|
36
|
+
return item unless item.nil?
|
37
|
+
raise Locabulary::Exceptions::ItemNotFoundError.new(predicate_name, term_label)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
private_constant :ItemForService
|
41
|
+
end
|
42
|
+
end
|
data/lib/locabulary/services.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'active_support/core_ext/string/inflections'
|
2
|
-
require 'locabulary/services/
|
3
|
-
require 'locabulary/services/
|
4
|
-
require 'locabulary/services/
|
2
|
+
require 'locabulary/services/build_ordered_hierarchical_tree_service'
|
3
|
+
require 'locabulary/services/active_items_for_service'
|
4
|
+
require 'locabulary/services/active_hierarchical_roots_service'
|
5
|
+
require 'locabulary/services/item_for_service'
|
5
6
|
|
7
|
+
# :nodoc:
|
6
8
|
module Locabulary
|
7
9
|
# @api private
|
8
10
|
#
|
@@ -20,8 +22,9 @@ module Locabulary
|
|
20
22
|
# @param command_name [Symbol]
|
21
23
|
# @param options [Hash]
|
22
24
|
def self.call(command_name, options = {})
|
23
|
-
command_class = "#{command_name}
|
25
|
+
command_class = "#{command_name}_service".classify
|
24
26
|
const_get(command_class).call(options)
|
25
27
|
end
|
26
28
|
end
|
29
|
+
private_constant :Services
|
27
30
|
end
|
data/lib/locabulary/utility.rb
CHANGED
@@ -8,6 +8,14 @@ module Locabulary
|
|
8
8
|
# underlying data sources.
|
9
9
|
module Utility
|
10
10
|
DATA_DIRECTORY = File.expand_path("../../../data/", __FILE__).freeze
|
11
|
+
# @api private
|
12
|
+
#
|
13
|
+
# Extract and yield data for the given :predicate_name from the data storage. Only yield data that is active on the :as_of date
|
14
|
+
#
|
15
|
+
# @param predicate_name [String]
|
16
|
+
# @param as_of [Date]
|
17
|
+
# @yield Raw data object that conforms to the Locabulary::Schema definition
|
18
|
+
# @see Locabulary::Schema
|
11
19
|
def self.with_active_extraction_for(predicate_name, as_of)
|
12
20
|
json = JSON.parse(File.read(filename_for_predicate_name(predicate_name)))
|
13
21
|
json.fetch('values').each do |data|
|
@@ -15,6 +23,13 @@ module Locabulary
|
|
15
23
|
end
|
16
24
|
end
|
17
25
|
|
26
|
+
# @api private
|
27
|
+
#
|
28
|
+
# Extract and yield data for the given :predicate_name from the data storage.
|
29
|
+
#
|
30
|
+
# @param predicate_name [String]
|
31
|
+
# @yield Raw data object that conforms to the Locabulary::Schema definition for a single value
|
32
|
+
# @see Locabulary::Schema
|
18
33
|
def self.with_extraction_for(predicate_name)
|
19
34
|
json = JSON.parse(File.read(filename_for_predicate_name(predicate_name)))
|
20
35
|
json.fetch('values').each do |data|
|
@@ -22,6 +37,14 @@ module Locabulary
|
|
22
37
|
end
|
23
38
|
end
|
24
39
|
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
# Determines if the data is active or not active
|
43
|
+
#
|
44
|
+
# @param data [Hash] conforms to the Locabulary::Schema definition for a single value
|
45
|
+
# @param as_of [Date]
|
46
|
+
# @return [Boolean]
|
47
|
+
# @see Locabulary::Schema
|
25
48
|
def self.data_is_active?(data, as_of)
|
26
49
|
activated_on = Date.parse(data.fetch('activated_on'))
|
27
50
|
return false unless activated_on < as_of
|
@@ -32,6 +55,12 @@ module Locabulary
|
|
32
55
|
true
|
33
56
|
end
|
34
57
|
|
58
|
+
# @api private
|
59
|
+
#
|
60
|
+
# Returns the filename of the file that contains the data for the given :predicate_name
|
61
|
+
#
|
62
|
+
# @param predicate_name [String]
|
63
|
+
# @return [String] name of file that contains the data for the given predicate
|
35
64
|
def self.filename_for_predicate_name(predicate_name)
|
36
65
|
filename = File.join(DATA_DIRECTORY, "#{File.basename(predicate_name)}.json")
|
37
66
|
return filename if File.exist?(filename)
|
data/lib/locabulary/version.rb
CHANGED
data/lib/locabulary.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
require 'date'
|
2
|
-
require 'json'
|
3
|
-
require 'locabulary/exceptions'
|
4
|
-
require 'locabulary/item'
|
5
1
|
require 'locabulary/services'
|
6
2
|
|
7
3
|
# @since 0.1.0
|
4
|
+
# @api public
|
5
|
+
#
|
6
|
+
# Locabulary is structured to expose public interface methods in the base module (e.g. `Locabulary`).
|
7
|
+
# Other things to consider are the Locabulary::Items::Base object as it defines the returned data structure
|
8
|
+
# for the public Locabulary methods.
|
9
|
+
#
|
10
|
+
# @see Locabury::Items::Base
|
8
11
|
module Locabulary
|
9
12
|
# @api public
|
10
13
|
# @since 0.5.0
|
@@ -48,6 +51,7 @@ module Locabulary
|
|
48
51
|
# @option options [String] :predicate_name
|
49
52
|
# @option options [Date] :as_of (Date.today)
|
50
53
|
# @return [Array<Locabulary::Items::Base>] - the root nodes
|
54
|
+
#
|
51
55
|
# @see Locabulary::Services
|
52
56
|
def self.active_hierarchical_roots(options = {})
|
53
57
|
Services.call(:active_hierarchical_roots, options)
|
@@ -65,23 +69,17 @@ module Locabulary
|
|
65
69
|
# @option options [Date] :as_of (Date.today)
|
66
70
|
# @raise [Locabulary::Exceptions::ItemNotFoundError] if unable to find label for predicate_name
|
67
71
|
# @return [Locabulary::Items::Base]
|
72
|
+
#
|
73
|
+
# @see Locabulary::Services
|
68
74
|
def self.item_for(options = {})
|
69
|
-
|
70
|
-
term_label = options.fetch(:term_label)
|
71
|
-
as_of = options.fetch(:as_of) { Date.today }
|
72
|
-
item = nil
|
73
|
-
Utility.with_extraction_for(predicate_name) do |data|
|
74
|
-
next unless data.fetch('term_label') == term_label
|
75
|
-
item = Item.build(data.merge('predicate_name' => predicate_name))
|
76
|
-
break if Utility.data_is_active?(data, as_of)
|
77
|
-
end
|
78
|
-
return item unless item.nil?
|
79
|
-
raise Locabulary::Exceptions::ItemNotFoundError.new(predicate_name, term_label)
|
75
|
+
Services.call(:item_for, options)
|
80
76
|
end
|
81
77
|
|
82
78
|
# @api public
|
83
79
|
# @since 0.1.0
|
84
80
|
#
|
81
|
+
# For the given :predicate_name and :term_uri return a best fitting human readable label.
|
82
|
+
#
|
85
83
|
# @param [Hash] options
|
86
84
|
# @option options [String] :predicate_name
|
87
85
|
# @option options [String] :term_uri
|
data/locabulary.gemspec
CHANGED
@@ -20,10 +20,16 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.license = 'APACHE2'
|
21
21
|
|
22
22
|
spec.add_dependency "json", "~> 1.8"
|
23
|
-
spec.add_dependency "dry-configurable"
|
23
|
+
spec.add_dependency "dry-configurable", "~> 0.1.7"
|
24
24
|
spec.add_dependency "activesupport", '~>4.0'
|
25
25
|
|
26
|
-
spec.add_development_dependency "dry-validation"
|
26
|
+
spec.add_development_dependency "dry-validation", "~> 0.9.5"
|
27
|
+
spec.add_development_dependency "dry-logic", "~> 0.3.0"
|
28
|
+
spec.add_development_dependency "dry-types", "~> 0.8.1"
|
29
|
+
spec.add_development_dependency "dry-container", "~> 0.5.0"
|
30
|
+
spec.add_development_dependency "dry-equalizer", "~> 0.2.0"
|
31
|
+
spec.add_development_dependency "dry-monads", "~> 0.1.1"
|
32
|
+
|
27
33
|
spec.add_development_dependency "bundler"
|
28
34
|
spec.add_development_dependency "rspec"
|
29
35
|
spec.add_development_dependency "rspec-its"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locabulary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: dry-configurable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.1.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.1.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,86 @@ dependencies:
|
|
56
56
|
name: dry-validation
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.9.5
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.9.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dry-logic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dry-types
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dry-container
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.5.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.5.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dry-equalizer
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.2.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.2.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: dry-monads
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.1.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.1.1
|
69
139
|
- !ruby/object:Gem::Dependency
|
70
140
|
name: bundler
|
71
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -268,9 +338,10 @@ files:
|
|
268
338
|
- lib/locabulary/json_creator.rb
|
269
339
|
- lib/locabulary/schema.rb
|
270
340
|
- lib/locabulary/services.rb
|
271
|
-
- lib/locabulary/services/
|
272
|
-
- lib/locabulary/services/
|
273
|
-
- lib/locabulary/services/
|
341
|
+
- lib/locabulary/services/active_hierarchical_roots_service.rb
|
342
|
+
- lib/locabulary/services/active_items_for_service.rb
|
343
|
+
- lib/locabulary/services/build_ordered_hierarchical_tree_service.rb
|
344
|
+
- lib/locabulary/services/item_for_service.rb
|
274
345
|
- lib/locabulary/utility.rb
|
275
346
|
- lib/locabulary/version.rb
|
276
347
|
- locabulary.gemspec
|
@@ -303,4 +374,3 @@ signing_key:
|
|
303
374
|
specification_version: 4
|
304
375
|
summary: An extraction of limited localized vocabulary for Sipity and CurateND.
|
305
376
|
test_files: []
|
306
|
-
has_rdoc:
|