locabulary 0.2.0 → 0.3.0

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.
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hanami-utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: dry-validation
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +81,21 @@ dependencies:
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: minitest
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - ">="
@@ -122,6 +164,48 @@ dependencies:
122
164
  - - "~>"
123
165
  - !ruby/object:Gem::Version
124
166
  version: '4.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: codeclimate-test-reporter
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
125
209
  description: An extraction of limited localized vocabulary for Sipity and CurateND.
126
210
  email:
127
211
  - jeremy.n.friesen@gmail.com
@@ -130,6 +214,10 @@ extensions: []
130
214
  extra_rdoc_files: []
131
215
  files:
132
216
  - ".gitignore"
217
+ - ".hound.yml"
218
+ - ".rspec"
219
+ - ".rubocop_todo.yml"
220
+ - ".ruby-version"
133
221
  - ".travis.yml"
134
222
  - CODE_OF_CONDUCT.md
135
223
  - Gemfile
@@ -152,9 +240,14 @@ files:
152
240
  - data/work_patent_strategy.json
153
241
  - data/work_publication_strategy.json
154
242
  - lib/locabulary.rb
243
+ - lib/locabulary/exceptions.rb
244
+ - lib/locabulary/items.rb
245
+ - lib/locabulary/items/administrative_unit.rb
246
+ - lib/locabulary/items/base.rb
247
+ - lib/locabulary/json_creator.rb
155
248
  - lib/locabulary/schema.rb
249
+ - lib/locabulary/version.rb
156
250
  - locabulary.gemspec
157
- - script/json_creator.rb
158
251
  - script/update_data_files.sh
159
252
  homepage: https://github.com/ndlib/locabulary
160
253
  licenses:
@@ -1,129 +0,0 @@
1
- require "google/api_client"
2
- require "google_drive"
3
- require 'highline/import'
4
- require 'json'
5
-
6
- class JsonCreator
7
-
8
- ATTRIBUTE_NAMES = [:term_label, :term_uri, :deposit_label, :description, :grouping, :affiliation, :presentation_sequence, :activated_on, :deactivated_on].freeze
9
-
10
- attr_reader(*ATTRIBUTE_NAMES)
11
-
12
- def initialize(document_key, vocabulary, data_fetcher = default_data_fetcher)
13
- @document_key = document_key
14
- @vocabulary = vocabulary
15
- @output_filepath = "data/#{vocabulary}.json"
16
- @data_fetcher = data_fetcher
17
- end
18
-
19
- attr_reader :document_key, :vocabulary, :data_fetcher, :spreadsheet_data, :json_data
20
- attr_accessor :output_filepath
21
- ORDER = {
22
- "University" => 100,
23
- "College" => 200,
24
- "Center" => 500,
25
- "Department" => 300,
26
- "Institute" => 400
27
- }
28
-
29
-
30
-
31
- def create_or_update
32
- @spreadsheet_data = data_fetcher.call(document_key)
33
- convert_to_json(get_required_data_from_spreadsheet)
34
- end
35
-
36
- def write_to_file
37
- File.open(output_filepath, "w") do |f|
38
- f.puts json_data
39
- end
40
- end
41
-
42
- private
43
-
44
- attr_writer(*ATTRIBUTE_NAMES)
45
-
46
- def default_data_fetcher
47
- ->(document_key) { GoogleSpreadsheet.new(document_key).read_spreadsheet }
48
- end
49
-
50
- class GoogleSpreadsheet
51
- attr_reader :access_token, :document_key
52
- FILE_PATH = __FILE__
53
-
54
- def initialize(document_key)
55
- @document_key = document_key
56
- configure_oauth!
57
- end
58
-
59
- def configure_oauth!
60
- client = Google::APIClient.new
61
- auth = client.authorization
62
- auth.client_id = client_secrets.fetch('client_id')
63
- auth.client_secret = client_secrets.fetch('client_secret')
64
- auth.scope = ["https://www.googleapis.com/auth/drive.readonly"]
65
- auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
66
- puts "\n Open the following URL, login with your credentials and get the authorization code \n\n #{auth.authorization_uri}\n\n"
67
- auth.code = ask('Authorization Code: ')
68
- auth.fetch_access_token!
69
- @access_token = auth.access_token
70
- end
71
-
72
- def read_spreadsheet
73
- session = GoogleDrive.login_with_oauth(access_token)
74
- ws = session.spreadsheet_by_key(document_key).worksheets[0]
75
- spreadsheet_data = []
76
- (1..ws.num_rows).each do |row|
77
- row_data = []
78
- (1..ws.num_cols).each do |col|
79
- row_data << ws[row, col]
80
- end
81
- spreadsheet_data << row_data
82
- end
83
- spreadsheet_data
84
- end
85
-
86
- def client_secrets
87
- return @secrets if @secrets
88
- secrets_path = File.join(File.dirname(FILE_PATH), '../config/client_secrets.example.yml')
89
- secrets_path = File.join(File.dirname(FILE_PATH), '../config/client_secrets.yml') if File.exist? File.join(File.dirname(FILE_PATH), '../config/client_secrets.yml')
90
- @secrets = YAML.load(File.open(File.join(secrets_path)))
91
- end
92
- end
93
-
94
- def get_required_data_from_spreadsheet
95
- formatted_data =[]
96
- line = []
97
- spreadsheet_data.shift
98
- spreadsheet_data.each do |row|
99
- final = {}
100
- line << row[0]
101
- line << row[1] if row[1] && !row[1].empty?
102
- line << row[2] if row[2] && !row[2].empty?
103
- final[ "term_label" ] = line.join('::')
104
- final[ "presentation_sequence" ] = ORDER[row[3]]
105
- final[ "term_uri" ] = row[4]
106
- final[ "deposit_label" ] = row[5]
107
- final[ "description" ] = row[6]
108
- final[ "grouping" ] = row[7]
109
- final[ "affiliation" ] = row[8]
110
- final[ "activated_on" ] = "2015-07-22"
111
- final[ "deactivated_on" ] = nil
112
- formatted_data << final
113
- line = []
114
- end
115
- formatted_data
116
- end
117
-
118
- def convert_to_json(data)
119
- json_array = []
120
- data.each do |row|
121
- data_map = {"predicate_name"=>vocabulary}
122
- ATTRIBUTE_NAMES.each do |key|
123
- data_map[ key ] = row.fetch(key) { row.fetch(key.to_s, nil) }
124
- end
125
- json_array << data_map
126
- end
127
- @json_data = JSON.pretty_generate({"predicate_name"=>vocabulary, "values"=> json_array})
128
- end
129
- end