cotcube-helpers 0.1.9.2 → 0.1.10

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
2
  SHA256:
3
- metadata.gz: 2bfb21e47e19a7dfd33125d42d4d049d8654fbf84e36edfe081a3878e751439e
4
- data.tar.gz: 847d6eb7b98df85dc11aadc294147542071fdb4ff83d86faac3e0ef14d204d47
3
+ metadata.gz: e00fe82276d1be8a2f034759240a0bf820574f6c99de4ec6126bf436bf6a149b
4
+ data.tar.gz: e512de0546fd46dcdb356a55265bb8bc874999447c98df67c77b1289a8e2cee4
5
5
  SHA512:
6
- metadata.gz: b2a0020f5c8277b6882dbe7a00e2c885c1e86eb56b22529236b086554b7b69b398afaa1b013bb02b8f4d23f7a7444000dac77e283c7c92ecaa8e2e255e44c6f9
7
- data.tar.gz: b8638126b407e5c4e74a0866fa7497d1c3f29af6f143b94fbca775987de78f350df75b239fd68dcc339aaa4858254b5957c3b9a1e4a4aff40d8c3b487a84a5b4
6
+ metadata.gz: 5c0474d0638810ecf7af38f662c80c9a91ac531e5d38e71ff03e7872b559a4add577437c91c435ace0a8b1afc2adb1c1b686272426b6404d138d9d7b3fdfa8af
7
+ data.tar.gz: 94b42e991e539ac38e672c0fea5aba4a052e9c5a2b3899bc48d3e855ce23541f04f3b8a8640bb9bb76bd144476e4110d226e4a28298c66ad45480b3d80031a51
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.1.10 (October 28, 2021)
2
+ - added script cron_ruby_wrapper.sh (linkable as /usr/local/bin/cruw.sh)
3
+ - added numeric ext .with_delimiter to support printing like 123_456_789.00121
4
+ - added micros to module
5
+ - added Helpers.micros to symbols.rb
6
+ - subpattern: excaping regex pattern to avoid ESC errors
7
+ - minor change
8
+
1
9
  ## 0.1.9.2 (July 24, 2021)
2
10
  - added missing module_functions
3
11
  - init: minor fix
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9.2
1
+ 0.1.10
@@ -3,8 +3,13 @@
3
3
  module Cotcube
4
4
  module Helpers
5
5
  SYMBOL_EXAMPLES = [
6
- { id: '13874U', symbol: 'ET', ticksize: 0.25, power: 1.25, months: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'S&P 500 MICRO' },
7
- { id: '209747', symbol: 'NM', ticksize: 0.25, power: 0.5, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'NASDAQ 100 MICRO' }
6
+ { id: '13874U', symbol: 'ES', ticksize: 0.25, power: 12.5, months: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'S&P 500 MICRO' },
7
+ { id: '209747', symbol: 'NQ', ticksize: 0.25, power: 5.0, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'NASDAQ 100 MICRO' }
8
+ ].freeze
9
+
10
+ MICRO_EXAMPLES = [
11
+ { id: '13874U', symbol: 'ET', ticksize: 0.25, power: 1.25, months: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'MICRO S&P 500 MICRO' },
12
+ { id: '209747', symbol: 'NM', ticksize: 0.25, power: 0.5, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'MICRO NASDAQ 100 MICRO' }
8
13
  ].freeze
9
14
 
10
15
  COLORS = %i[light_red light_yellow light_green red yellow green cyan magenta blue].freeze
@@ -18,9 +23,9 @@ module Cotcube
18
23
  'J' => 4, 'K' => 5, 'M' => 6,
19
24
  'N' => 7, 'Q' => 8, 'U' => 9,
20
25
  'V' => 10, 'X' => 11, 'Z' => 12,
21
- 1 => 'F', 2 => 'G', 3 => 'H',
22
- 4 => 'J', 5 => 'K', 6 => 'M',
23
- 7 => 'N', 8 => 'Q', 9 => 'U',
26
+ 1 => 'F', 2 => 'G', 3 => 'H',
27
+ 4 => 'J', 5 => 'K', 6 => 'M',
28
+ 7 => 'N', 8 => 'Q', 9 => 'U',
24
29
  10 => 'V', 11 => 'X', 12 => 'Z' }.freeze
25
30
 
26
31
 
@@ -3,12 +3,13 @@
3
3
  module Cotcube
4
4
  module Helpers
5
5
 
6
- def get_id_set(symbol: nil, id: nil, contract: nil, config: init)
6
+ def get_id_set(symbol: nil, id: nil, contract: nil, config: init, mini: false, micro: false)
7
+ micro = mini || micro
7
8
  contract = contract.to_s.upcase if contract.is_a? Symbol
8
9
  id = id.to_s.upcase if id.is_a? Symbol
9
10
  symbol = symbol.to_s.upcase if symbol.is_a? Symbol
10
11
 
11
- if contract.is_a?(String) && (contract.length == 5)
12
+ if contract.is_a?(String) && ([2,3,4,5].include? contract.length)
12
13
  c_symbol = contract[0..1]
13
14
  if (not symbol.nil?) && (symbol != c_symbol)
14
15
  raise ArgumentError,
@@ -19,22 +20,22 @@ module Cotcube
19
20
  end
20
21
 
21
22
  unless symbol.nil?
22
- sym = symbols.select { |s| s[:symbol] == symbol.to_s.upcase }.first
23
+ sym = symbols(symbol: symbol)
23
24
  if sym.nil? || sym[:id].nil?
24
25
  raise ArgumentError,
25
26
  "Could not find match in #{config[:symbols_file]} for given symbol #{symbol}"
26
27
  end
27
28
  raise ArgumentError, "Mismatching symbol #{symbol} and given id #{id}" if (not id.nil?) && (sym[:id] != id)
28
29
 
29
- return sym
30
+ return micro ? micros(id: sym[:id]) : sym
30
31
  end
31
32
  unless id.nil?
32
- sym = symbols.select { |s| s[:id] == id.to_s }.first
33
+ sym = symbols(id: id)
33
34
  if sym.nil? || sym[:id].nil?
34
35
  raise ArgumentError,
35
36
  "Could not find match in #{config[:symbols_file]} for given id #{id}"
36
37
  end
37
- return sym
38
+ return micro ? micros(id: sym[:id]) : sym
38
39
  end
39
40
  raise ArgumentError, 'Need :id, :symbol or valid :contract '
40
41
  end
@@ -23,10 +23,11 @@ module Cotcube
23
23
  gem_name: nil,
24
24
  debug: false)
25
25
  gem_name ||= self.ancestors.first.to_s
26
- config_file_name = "#{gem_name.downcase}.yml"
26
+ config_file_name = "#{gem_name.downcase.split('::').last}.yml"
27
27
  config_file = config_path + "/#{config_file_name}"
28
28
 
29
29
  if File.exist?(config_file)
30
+ require 'yaml'
30
31
  config = YAML.load(File.read config_file).transform_keys(&:to_sym)
31
32
  else
32
33
  config = {}
@@ -0,0 +1,8 @@
1
+ class Numeric
2
+ def with_delimiter(deli=nil)
3
+ raise ArgumentError, "Param delimiter can't be nil" if deli.nil?
4
+ pre, post = self.to_s.split('.')
5
+ pre = pre.chars.to_a.reverse.each_slice(3).map(&:join).join(deli).reverse
6
+ post.nil? ? pre : [pre,post].join('.')
7
+ end
8
+ end
@@ -22,12 +22,12 @@ module Cotcube
22
22
  lambda do |x|
23
23
  return false if x.nil? || (x.size < minimum)
24
24
 
25
- return ((pattern =~ /^#{x}/i).nil? ? false : true)
25
+ return ((pattern =~ /^#{Regexp.escape x}/i).nil? ? false : true)
26
26
  end
27
27
  when Array
28
28
  pattern.map do |x|
29
29
  unless [String, Symbol, NilClass].include? x.class
30
- raise TypeError, "Unsupported class '#{x.class}' for '#{x}'in pattern '#{pattern}'."
30
+ raise TypeError, "Unsupported class '#{x.class}' for '#{x}' in pattern '#{pattern}'."
31
31
  end
32
32
  end
33
33
  lambda do |x|
@@ -35,13 +35,13 @@ module Cotcube
35
35
  sub = sub.to_s
36
36
  return false if x.size < minimum
37
37
 
38
- result = ((sub =~ /^#{x}/i).nil? ? false : true)
38
+ result = ((sub =~ /^#{Regexp.escape x}/i).nil? ? false : true)
39
39
  return true if result
40
40
  end
41
41
  return false
42
42
  end
43
43
  else
44
- raise TypeError, "Unsupported class #{pattern.class} in Cotcube::Core::sub"
44
+ raise TypeError, "Unsupported class #{pattern.class} in Cotcube::Helpers::sub"
45
45
  end
46
46
  end
47
47
  end
@@ -4,7 +4,7 @@ module Cotcube
4
4
  # Missing top level documentation
5
5
  module Helpers
6
6
 
7
- def symbols(config: init, type: nil, symbol: nil)
7
+ def symbols(config: init, type: nil, symbol: nil, id: nil)
8
8
  if config[:symbols_file].nil?
9
9
  SYMBOL_EXAMPLES
10
10
  else
@@ -13,10 +13,25 @@ module Cotcube
13
13
  .map{|row| row.to_h }
14
14
  .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row[:format] = "%#{row[:format]}f"; row }
15
15
  .reject{|row| row[:id].nil? }
16
- .tap{|all| all.select!{|x| x[:type] == type} unless type.nil? }
17
- .tap { |all| all.select! { |x| x[:symbol] == symbol } unless symbol.nil? }
16
+ .tap { |all| all.select!{|x| x[:type] == type} unless type.nil? }
17
+ .tap { |all| (return all.select { |x| x[:symbol] == symbol }.first ) unless symbol.nil? }
18
+ .tap{ |all| (return all.select { |x| x[:id] == id }.first) unless id.nil? }
18
19
  end
19
20
  end
20
21
 
22
+ def micros(config: init, symbol: nil, id: nil)
23
+ if config[:micros_file].nil?
24
+ MICRO_EXAMPLES
25
+ else
26
+ CSV
27
+ .read(config[:micros_file], headers: %i{ id symbol ticksize power months type bcf reports format name})
28
+ .map{|row| row.to_h }
29
+ .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row[:format] = "%#{row[:format]}f"; row }
30
+ .reject{|row| row[:id].nil? }
31
+ .tap{ |all| (return all.select { |x| x[:symbol] == symbol }.first) unless symbol.nil? }
32
+ .tap{ |all| (return all.select { |x| x[:id] == id }.first) unless id.nil? }
33
+ end
34
+ end
21
35
  end
36
+
22
37
  end
@@ -6,6 +6,7 @@ require 'active_support'
6
6
  require 'active_support/core_ext/time'
7
7
  require 'active_support/core_ext/numeric'
8
8
  require 'parallel'
9
+ require 'csv'
9
10
 
10
11
  require_relative 'cotcube-helpers/array_ext'
11
12
  require_relative 'cotcube-helpers/enum_ext'
@@ -13,6 +14,7 @@ require_relative 'cotcube-helpers/hash_ext'
13
14
  require_relative 'cotcube-helpers/range_ext'
14
15
  require_relative 'cotcube-helpers/string_ext'
15
16
  require_relative 'cotcube-helpers/datetime_ext'
17
+ require_relative 'cotcube-helpers/numeric_ext'
16
18
  require_relative 'cotcube-helpers/subpattern'
17
19
  require_relative 'cotcube-helpers/parallelize'
18
20
  require_relative 'cotcube-helpers/simple_output'
@@ -34,6 +36,7 @@ module Cotcube
34
36
  :simple_series_stats,
35
37
  :keystroke,
36
38
  :symbols,
39
+ :micros,
37
40
  :get_id_set,
38
41
  :init
39
42
 
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+
3
+ export rubyenv=/home/pepe/.rvm/environments/default
4
+
5
+ . $rubyenv
6
+ cd /home/pepe/GEMS/${1}
7
+ export LC_ALL="en_US.utf8"
8
+
9
+ ruby ${2} ${3} ${4} ${5} ${6}
10
+
11
+
12
+ exit
13
+ for testing run
14
+ env - `cat /home/pepe/bin/cron_ruby_wrapper.sh | tail -n 6` /bin/bash
15
+
16
+ HOME=/home/pepe
17
+ LOGNAME=pepe
18
+ PATH=/usr/bin:/bin
19
+ LANG=en_US.UTF-8
20
+ SHELL=/bin/sh
21
+ PWD=/home/pepe
22
+
23
+
24
+
25
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9.2
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-24 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -103,6 +103,7 @@ files:
103
103
  - lib/cotcube-helpers/hash_ext.rb
104
104
  - lib/cotcube-helpers/init.rb
105
105
  - lib/cotcube-helpers/input.rb
106
+ - lib/cotcube-helpers/numeric_ext.rb
106
107
  - lib/cotcube-helpers/parallelize.rb
107
108
  - lib/cotcube-helpers/range_ext.rb
108
109
  - lib/cotcube-helpers/reduce.rb
@@ -114,6 +115,7 @@ files:
114
115
  - lib/cotcube-helpers/swig/fill_x.rb
115
116
  - lib/cotcube-helpers/swig/recognition.rb
116
117
  - lib/cotcube-helpers/symbols.rb
118
+ - scripts/cron_ruby_wrapper.sh
117
119
  homepage: https://github.com/donkeybridge/cotcube-helpers
118
120
  licenses:
119
121
  - BSD-4-Clause