tricorder 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 171d739dab9839ce2f0be74b57694a1876d063d5089cdb0d90b2090984e88346
4
- data.tar.gz: fe3b21010cedcb7ef2a08fa94ce002eb90bfaaf9c48c269e4e0b60e8610f2e66
3
+ metadata.gz: 17622b879e8001783e06b09fd71ed0c34a12eefd1d2e37e0d09db7a8c3b11892
4
+ data.tar.gz: 997bd53c65e73aa74c445106ecee68d2e3a55ec5af72bf836b55652909e658c7
5
5
  SHA512:
6
- metadata.gz: 4f91847fe743bfb9a2153d4e1c906235abf15b3f7a174c7740bd35e548e42af685603976ca101a4d16a0508e5ac415cc0990e960776eb9337621f05e9b09a740
7
- data.tar.gz: e74154e4d1a80bba53d4010bdeedcdf2dbd1117365b7bcd080dfc3842b73cc66f8ee972bb588646963ce1e964c5649c3795874466edc0de5507bb0c46a50a4ca
6
+ metadata.gz: d4ac54adba195400866abeb71029857e3f98153f2add719177d2a85ebda967d1bbac523b5e7bbf3e9942ad4110d1e217d7bb1f41e70753519fd9bb0bc6140ac2
7
+ data.tar.gz: 7321184774c0659be40b57b817df2d7713885ed8480adf7ddc121d7500101f665574e1bf0e4db33a1a3b6adc481d72fce77079e1bde429923f526de2d6476efa
data/README.md CHANGED
@@ -41,6 +41,20 @@ $ tricorder search Uhura --database character --print-only-once --print-info=cha
41
41
  Human
42
42
  ```
43
43
 
44
+ To use a plugin use the `--preprocessor`
45
+
46
+ ```
47
+ $ tricorder search Uhura --disable-logging --database character --print-only-once --print-info=characterSpecies name --preprocessor name2klingon printobject scope2klingon --format raw
48
+ 0xF8DB 0xF8E8 0xF8DD 0xF8E3 0xF8D0 0xF8E5 0xF8D6 0xF8E5 0xF8E1 0xF8D0
49
+ Human
50
+ 0xF8D6 0xF8E5 0xF8DA 0xF8D0 0xF8DB
51
+ ```
52
+
53
+ To set the format output, use the `--format` command, available formats are `plain`, `raw`, `json` and `html`
54
+ ```
55
+ tricorder search Uhura --database character --format html
56
+ ```
57
+
44
58
  ## Domain Specific Language
45
59
  Here's an example of using tricorder programmatically via it's own DSL syntax,
46
60
 
@@ -20,6 +20,8 @@ module Tricorder
20
20
  option :print_only_once, type: :boolean, desc: 'Disable printing multiple info results'
21
21
  option :print_info, type: :array, desc: 'Print info scope. i.e. --print-info=characterSpecies name'
22
22
  option :print_details, type: :boolean, desc: 'Print all the details of each queried info'
23
+ option :format, type: :string, desc: 'Output format as plain (default), json, html, raw'
24
+ option :preprocessor, type: :array, desc: 'Use a pre-processor i.e. --preprocessor name2klingon printobject scope2klingon'
23
25
 
24
26
  desc 'search <keyword>', 'Perform search in Star Trek API on all databases'
25
27
  def search(keyword)
@@ -33,6 +35,8 @@ module Tricorder
33
35
  command += ".no_logging" if options[:disable_logging]
34
36
  command += ".api_key('#{options[:api_key]}')" if options[:api_key]
35
37
  command += ".print_only_once" if options[:print_only_once]
38
+ command += ".set_format('#{options[:format]}')" if options[:format]
39
+ command += ".preprocessor(#{options[:preprocessor]})" if options[:preprocessor]
36
40
  command += ".search_locations(#{locations})"
37
41
  command += ".get_result_number(#{options[:result_number]})" if options[:result_number]
38
42
  command += ".print_all_results" unless options[:result_number] || options[:print_only_once]
@@ -1,4 +1,5 @@
1
1
  require_relative 'tricorders'
2
+ require_relative 'plugins'
2
3
 
3
4
  module BaseOperators
4
5
  include Tricorders
@@ -44,6 +45,12 @@ module BaseOperators
44
45
  self
45
46
  end
46
47
 
48
+ def preprocessor(*preprocessors)
49
+ @preprocessors = preprocessors.flatten
50
+
51
+ self
52
+ end
53
+
47
54
  def log(message, options = {})
48
55
  return unless options[:verbose] || @verbose
49
56
 
@@ -141,6 +148,19 @@ module BaseOperators
141
148
  end
142
149
  end
143
150
 
151
+ def set_format(type)
152
+ formats = [:raw, :plain, :json, :html]
153
+
154
+ if formats.include?(type.to_sym)
155
+ @format = type.to_sym
156
+ else
157
+ ap "Invalid format #{@format}. Valid formats are #{formats.join(', ')}"
158
+ @error = true
159
+ end
160
+
161
+ self
162
+ end
163
+
144
164
  def search
145
165
  exit(0) if @error
146
166
 
@@ -192,10 +212,18 @@ module BaseOperators
192
212
 
193
213
  init_error_messages
194
214
 
215
+ @object = object
216
+
195
217
  if object.empty?
196
- "No info found!"
218
+ ap "No info found!"
197
219
  else
198
- object
220
+ if @preprocessors
221
+ @preprocessors.each do |preprocessor|
222
+ self.send(preprocessor.to_sym) unless self.instance_variable_get("@#{preprocessor}".to_sym)
223
+ end
224
+ else
225
+ print_object
226
+ end
199
227
  end
200
228
  end
201
229
 
@@ -208,7 +236,7 @@ module BaseOperators
208
236
 
209
237
  fetch_info
210
238
  begin
211
- info = printer(@info[@tricorder.to_s])
239
+ info = @info[@tricorder.to_s]
212
240
 
213
241
  print_info = if field
214
242
  info[collection][num][field]
@@ -222,7 +250,7 @@ module BaseOperators
222
250
  @out = print_info
223
251
  end
224
252
 
225
- log(@out, {pager: :puts, verbose: true}) unless @printed
253
+ printer(@out) unless @printed
226
254
 
227
255
  @printed = true if @print_only_once
228
256
  rescue
@@ -239,20 +267,20 @@ module BaseOperators
239
267
  set_uid(result['uid'])
240
268
 
241
269
  fetch_info
242
- ap printer(@info)
270
+ printer(@info)
243
271
  end
244
272
 
245
273
  self
246
274
  end
247
275
 
248
276
  def print_result
249
- ap printer(@result)
277
+ printer(@result)
250
278
 
251
279
  self
252
280
  end
253
281
 
254
282
  def print_all_results
255
- ap printer(@results)
283
+ printer(@results)
256
284
 
257
285
  self
258
286
  end
@@ -0,0 +1,7 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'plugins/**/*.rb')].sort.reverse.each { |plugin| require_relative plugin }
2
+
3
+ module Tricorders
4
+ include Name2Klingon
5
+ include Scope2Klingon
6
+ include PrintObject
7
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../../tricorder'
2
+ require_relative '../../tricorder_dsl'
3
+ require_relative 'pIqaD​_alphabet'
4
+
5
+ module Name2Klingon
6
+ include PiqadAlphabet
7
+
8
+ def name2klingon
9
+ @name2klingon = true
10
+ @output = []
11
+
12
+ output = @results[0]['name'].scan(/.{1}/)
13
+
14
+ output.each_with_index do |val, idx|
15
+ @output[idx] = KLINGON_LETTERS[val.upcase.to_sym]
16
+ end
17
+
18
+ puts @output.join(' ')
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ module PiqadAlphabet
2
+ KLINGON_LETTERS = {
3
+ A: '0xF8D0',
4
+ B: '0xF8D1',
5
+ CH: '0xF8D2',
6
+ D: '0xF8D3',
7
+ E: '0xF8D4',
8
+ GH: '0xF8D5',
9
+ H: '0xF8D6',
10
+ I: '0xF8D7',
11
+ J: '0xF8D8',
12
+ L: '0xF8D9',
13
+ M: '0xF8DA',
14
+ N: '0xF8DB',
15
+ NG: '0xF8DC',
16
+ O: '0xF8DD',
17
+ P: '0xF8DE',
18
+ Q: '0xF8DF',
19
+ QH: '0xF8E0',
20
+ R: '0xF8E1',
21
+ S: '0xF8E2',
22
+ T: '0xF8E3',
23
+ TLH: '0xF8E4',
24
+ U: '0xF8E5',
25
+ V: '0xF8E6',
26
+ W: '0xF8E7',
27
+ Y: '0xF8E8',
28
+ GLOTTALDASH: '0xF8E9'
29
+ }
30
+
31
+ KLINGON_DIGITS = {
32
+ ZERO: '0xF8F0',
33
+ ONE: '0xF8F1',
34
+ TWO: '0xF8F2',
35
+ THREE: '0xF8F3',
36
+ FOUR: '0xF8F4',
37
+ FIVE: '0xF8F5',
38
+ SIX: '0xF8F6',
39
+ SEVEN: '0xF8F7',
40
+ EIGHT: '0xF8F8',
41
+ NINE: '0xF8F9'
42
+ }
43
+
44
+ KLINGON_SYMBOLS = {
45
+ COMMA: '0xF8FD',
46
+ FULLSTOP: '0xF8FE',
47
+ MUMMIFICATIONGLYPH: '0xF8FF'
48
+ }
49
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../../tricorder'
2
+ require_relative '../../tricorder_dsl'
3
+
4
+ module PrintObject
5
+ def printobject
6
+ case @format
7
+ when :plain
8
+ ap @object
9
+ when :json
10
+ ap @object, indent: 2,
11
+ index: false,
12
+ multiline: true,
13
+ plain: true,
14
+ raw: true,
15
+ sort_keys: true,
16
+ sort_vars: true
17
+ when :html
18
+ ap @object, html: true
19
+ when :raw
20
+ puts @object
21
+ end
22
+ end
23
+ alias_method :print_object, :printobject
24
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../tricorder'
2
+ require_relative '../../tricorder_dsl'
3
+ require_relative 'pIqaD​_alphabet'
4
+
5
+ module Scope2Klingon
6
+ include PiqadAlphabet
7
+
8
+ def scope2klingon
9
+ @scope2klingon = true
10
+ @output = []
11
+ return unless @object.is_a?(String)
12
+
13
+ output = @object.scan(/.{1}/)
14
+
15
+ output.each_with_index do |val, idx|
16
+ @output[idx] = KLINGON_LETTERS[val.upcase.to_sym]
17
+ end
18
+
19
+ puts @output.join(' ')
20
+ end
21
+ end
@@ -14,6 +14,8 @@ class TricorderDSL < BaseOperators::BaseDSLOperators
14
14
  @storedir = '/tmp'
15
15
  @tricorder = nil
16
16
  @info = {}
17
+ @format = :plain
18
+ @output = []
17
19
  end
18
20
 
19
21
  def method_missing(method, *args)
@@ -2,7 +2,7 @@ module Tricorder #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tricorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Bryan Juliano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-24 00:00:00.000000000 Z
11
+ date: 2018-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,11 @@ files:
94
94
  - bin/tricorder
95
95
  - lib/dsl/operators/.rb
96
96
  - lib/dsl/operators/base_operators.rb
97
+ - lib/dsl/operators/plugins.rb
98
+ - lib/dsl/operators/plugins/name2klingon.rb
99
+ - lib/dsl/operators/plugins/pIqaD_alphabet.rb
100
+ - lib/dsl/operators/plugins/print_object.rb
101
+ - lib/dsl/operators/plugins/scope2klingon.rb
97
102
  - lib/dsl/operators/string.rb
98
103
  - lib/dsl/operators/tricorders.rb
99
104
  - lib/dsl/operators/tricorders/animal.rb