opener-core 2.0.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 87117423cfca0b17170602c260fc9104ba2b45ac
4
- data.tar.gz: 9d4bb57cb373d9267e7919a931f8bbed7df2f674
2
+ SHA256:
3
+ metadata.gz: 5e21e457a99dcc64b76d2840230b2b3e7265e6f4af85e85a34cf3d4a906ac492
4
+ data.tar.gz: 887abb3273444413eaa746a8a113f4ebd64e20d936dfe742f5049758153aa688
5
5
  SHA512:
6
- metadata.gz: 82117f92f331dce2a4f0d59e4da78028afc67c2eac93710d8d87b0b5c9440aa2a3bae643a62c1880cc8687401437c6ad5cb96417dd6df6040a0e16bfad7d9712
7
- data.tar.gz: 005414617ad9a815772613340254c8d955c4c0b8a388587eb8f37f3dcd793b2df8c9c8babcfbda40baaebc4e8dd6c2173e439058c05a040e7ac97fbd8f3f2888
6
+ metadata.gz: 0ad70d679479832376301b1c8ce03a18bd5c8bc5149728ec9e3788e4321da05fd61784497f81bf7dc68846ecc6d791452d96fedbb57901c84e2a4c706488d67c
7
+ data.tar.gz: 5060d1a70ecf85d08e3608046be6e01ed439ea5eaff689b28601cd210cf6110aa090173c9a94bd5dbc1f2fb80c1538b47966fac47b05234f44a2b7c33a355134
data/README.md CHANGED
@@ -10,10 +10,6 @@ A Gem that provides commonly re-used functionality for the various OpeNER Gems.
10
10
  | Rubinius | >= 2.2 | >= 2.3.0 |
11
11
  | JRuby | >= 1.7 | >= 1.7.16 |
12
12
 
13
- For the resource switcher you'll need to have
14
- [libarchive](http://www.libarchive.org/) installed as it's used for unpacking
15
- archives.
16
-
17
13
  ## Installation
18
14
 
19
15
  You can install opener-core as a Gem by running:
@@ -5,9 +5,8 @@ require 'fileutils'
5
5
 
6
6
  require 'slop'
7
7
  require 'httpclient'
8
- require 'archive'
9
8
 
10
9
  require_relative 'core/version'
11
- require_relative 'core/opt_parser'
12
- require_relative 'core/resource_switcher'
13
10
  require_relative 'core/syslog'
11
+ require_relative 'core/language_error'
12
+ require_relative 'core/language_code'
@@ -0,0 +1,14 @@
1
+ module Opener
2
+ module Core
3
+ module LanguageCode
4
+ ##
5
+ # Converts a language code to a valid Ruby constant name.
6
+ #
7
+ # @return [String]
8
+ #
9
+ def self.constant_name(code)
10
+ return code.gsub(/\W+/, '_').upcase
11
+ end
12
+ end # LanguageCode
13
+ end # Core
14
+ end # Opener
@@ -0,0 +1,23 @@
1
+ module Opener
2
+ module Core
3
+ ##
4
+ # Error class that can be used by components whenever they encounter an
5
+ # unsupported language.
6
+ #
7
+ # @!attribute [r] language
8
+ # @return [String]
9
+ #
10
+ class UnsupportedLanguageError < StandardError
11
+ attr_reader :language
12
+
13
+ ##
14
+ # @param [String] language
15
+ #
16
+ def initialize(language)
17
+ @language = language
18
+
19
+ super("The language #{language.inspect} is not supported")
20
+ end
21
+ end # UnsupportedLanguageError
22
+ end # Core
23
+ end # Opener
@@ -1,5 +1,7 @@
1
1
  module Opener
2
2
  module Core
3
- VERSION = '2.0.0'
3
+
4
+ VERSION = '2.5.0'
5
+
4
6
  end
5
7
  end
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'slop', '~> 3.0'
22
22
  spec.add_dependency 'httpclient'
23
- spec.add_dependency 'archive'
24
23
 
25
24
  spec.add_development_dependency 'bundler'
26
25
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2021-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: archive
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'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +81,7 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  description: Gem that contains some low level generic functions for all OpeNER components.
98
- email:
84
+ email:
99
85
  executables: []
100
86
  extensions: []
101
87
  extra_rdoc_files: []
@@ -103,8 +89,8 @@ files:
103
89
  - LICENSE.txt
104
90
  - README.md
105
91
  - lib/opener/core.rb
106
- - lib/opener/core/opt_parser.rb
107
- - lib/opener/core/resource_switcher.rb
92
+ - lib/opener/core/language_code.rb
93
+ - lib/opener/core/language_error.rb
108
94
  - lib/opener/core/syslog.rb
109
95
  - lib/opener/core/version.rb
110
96
  - opener-core.gemspec
@@ -112,7 +98,7 @@ homepage: http://opener-project.github.com
112
98
  licenses:
113
99
  - Apache 2.0
114
100
  metadata: {}
115
- post_install_message:
101
+ post_install_message:
116
102
  rdoc_options: []
117
103
  require_paths:
118
104
  - lib
@@ -127,10 +113,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
113
  - !ruby/object:Gem::Version
128
114
  version: '0'
129
115
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.2.2
132
- signing_key:
116
+ rubyforge_project:
117
+ rubygems_version: 2.7.8
118
+ signing_key:
133
119
  specification_version: 4
134
120
  summary: Gem that contains some low level generic functions for all OpeNER components.
135
121
  test_files: []
136
- has_rdoc:
@@ -1,60 +0,0 @@
1
- module Opener
2
- module Core
3
- class OptParser
4
- attr_accessor :option_parser, :options
5
-
6
- def initialize(&block)
7
- @options = {}
8
- @option_parser = construct_option_parser(options, &block)
9
- end
10
-
11
- def parse(args)
12
- process(:parse, args)
13
- end
14
-
15
- def parse!(args)
16
- process(:parse!, args)
17
- end
18
-
19
- def pre_parse!(args)
20
- delete_double_dash = false
21
- process(:parse!, args, delete_double_dash)
22
- end
23
-
24
- def pre_parse(args)
25
- delete_double_dash = false
26
- process(:parse, args, delete_double_dash)
27
- end
28
-
29
- def self.parse(args)
30
- new.parse(args)
31
- end
32
-
33
- def self.parse!(args)
34
- new.parse!(args)
35
- end
36
-
37
- def self.pre_parse!(args)
38
- new.pre_parse!(args)
39
- end
40
-
41
- def self.pre_parse(args)
42
- new.pre_parse(args)
43
- end
44
-
45
- private
46
-
47
- def process(call, args, delete_double_dash=true)
48
- args.delete("--") if delete_double_dash
49
- option_parser.send(call, args)
50
- return options
51
- end
52
-
53
- def construct_option_parser(options, &block)
54
- raise NotImplementedError
55
- end
56
- end
57
-
58
- end
59
- end
60
-
@@ -1,128 +0,0 @@
1
- module Opener
2
- module Core
3
- ##
4
- # Class for downloading and extracting external resources such as
5
- # models/lexicons.
6
- #
7
- # @!attribute [r] http
8
- # @return [HTTPClient]
9
- #
10
- class ResourceSwitcher
11
- attr_reader :http
12
-
13
- def initialize
14
- @http = HTTPClient.new
15
- end
16
-
17
- ##
18
- # Adds extra CLI options to the given Slop instance.
19
- #
20
- # @param [Slop] slop
21
- #
22
- def bind(slop)
23
- slop.separator "\nResource Options:\n"
24
-
25
- slop.on :'resource-url=',
26
- 'URL pointing to a .zip/.tar.gz file to download',
27
- :as => String
28
-
29
- slop.on :'resource-path=',
30
- 'Path where the resources should be saved',
31
- :as => String
32
-
33
- # Hijack Slop's run block so we can inject our own code before it. This
34
- # is quite grotesque, but sadly the only way.
35
- old_runner = slop.instance_variable_get(:@runner)
36
-
37
- slop.run do |opts, args|
38
- if opts[:'resource-path'] and opts[:'resource-url']
39
- download_and_extract(opts[:'resource-url'], opts[:'resource-path'])
40
- end
41
-
42
- old_runner.call(opts, args)
43
- end
44
- end
45
-
46
- ##
47
- # @param [String] url
48
- # @param [String] path
49
- #
50
- def download_and_extract(url, path)
51
- filename = filename_from_url(url)
52
- temp_path = File.join(path, filename)
53
-
54
- create_directory(path)
55
-
56
- download(url, temp_path)
57
-
58
- Archive.extract(temp_path, path)
59
-
60
- remove_file(temp_path)
61
- end
62
-
63
- ##
64
- # Downloads the given file.
65
- #
66
- # @param [String] url
67
- # @param [String] path
68
- #
69
- def download(url, path)
70
- File.open(path, 'w', :encoding => Encoding::BINARY) do |handle|
71
- http.get(url) do |chunk|
72
- handle.write(chunk)
73
- end
74
- end
75
- end
76
-
77
- ##
78
- # Returns the filename of the file located at `url`.
79
- #
80
- # @param [String] url
81
- # @return [String]
82
- #
83
- def filename_from_url(url)
84
- headers = get_headers(url)
85
-
86
- unless headers['Content-Disposition']
87
- raise "The URL #{url.inspect} did not return a Content-Disposition " \
88
- "header. This header is required to figure out the filename"
89
- end
90
-
91
- matches = headers['Content-Disposition'].match(/filename=(.+)/)
92
-
93
- if !matches or !matches[1]
94
- raise 'No filename could be found in the Content-Disposition header'
95
- end
96
-
97
- return matches[1]
98
- end
99
-
100
- ##
101
- # Creates the path. This method mainly exists to make testing a bit
102
- # easier.
103
- #
104
- # @param [String] path
105
- #
106
- def create_directory(path)
107
- FileUtils.mkdir_p(path)
108
- end
109
-
110
- ##
111
- # Removes the given file, mainly exists to make testing easier.
112
- #
113
- # @param [String] path
114
- #
115
- def remove_file(path)
116
- File.unlink(path)
117
- end
118
-
119
- ##
120
- # @param [String] url
121
- # @return [Hash]
122
- #
123
- def get_headers(url)
124
- return http.head(url).headers
125
- end
126
- end # ResourceSwitcher
127
- end # Core
128
- end # Opener