cotcube-helpers 0.1.7.2 → 0.1.9.1

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: 273a697c87680d0c695c1617caa490bb89f7712688c60a772e109ccda91fc622
4
- data.tar.gz: c3f91ba72a275068527f0fdc9dc59026ecffacd63de1466df9a6df9b39c1104c
3
+ metadata.gz: cb81f4056cbca5f2a1630a3ddc3a63070bcf00030b78cad54163e9fca057aaaa
4
+ data.tar.gz: 80cfdd92008406204cabb9add25987d49c1c3ba28b32db5c935e743e1d276470
5
5
  SHA512:
6
- metadata.gz: 6017fee6976dbb5c9306fb783df42174bf0d88a6df33d7d4a3647f744d484358257380297970faf2c14897c506aa6b9e6dd383399f21a623e993572e50c76bf0
7
- data.tar.gz: 1f39b5c5ac1002e1596f6d9ca79c73524fce4ba574d4fec594912f4f37f14ec4e0bb53ef57d60b2b648e95c1c8d7193fa0e3b47a6262c11d882eea228c7a3509
6
+ metadata.gz: bedbd01706f4f4896acf7dc7258371c31ace12f81b8c65c6f0c057129b824d1b3087f806fe48bd8a38d0a2894c1028ec5113fa6a1f9abbd2036ea156a86ca266
7
+ data.tar.gz: c17bbb49e51ced51f8ef8edefa6a781dc54598fb8ed7912df41434b6702096567f495f0cd0c873efbe020e36132e9402ac9f336e4607b151d1a34ae4600a2c3f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.1.9.1 (May 07, 2021)
2
+ - moved 'get_id_set' to Cotcube::Helpers
3
+ - minor fix to suppress some warning during build
4
+
5
+ ## 0.1.9 (May 07, 2021)
6
+ - added constants, init and symbols to helpers
7
+
8
+ ## 0.1.8 (April 18, 2021)
9
+ - datetime_ext: Date.cw provides a range of (Date..Date) representing the according calendar week
10
+
11
+ ## 0.1.7.4 (March 13, 2021)
12
+ - hotfix on 0.1.7.3
13
+
14
+ ## 0.1.7.3 (March 13, 2021)
15
+ - array_ext: pairwise and triplewise now support saving result in latter members []=
16
+
1
17
  ## 0.1.7.2 (February 01, 2021)
2
18
  - adding #deep_freeze to Enumerable
3
19
  - range_ext: added #mod to modify an (actually) immutable range
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7.2
1
+ 0.1.9.1
@@ -26,9 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_dependency 'activesupport'
29
+ spec.add_dependency 'activesupport', '~> 6'
30
+ spec.add_dependency 'colorize', '~> 0.8'
30
31
 
31
- spec.add_development_dependency 'rake'
32
+
33
+ spec.add_development_dependency 'rake', '~> 13'
32
34
  spec.add_development_dependency 'rspec', '~>3.6'
33
35
  spec.add_development_dependency 'yard', '~>0.9'
34
36
  end
@@ -19,6 +19,10 @@ require_relative 'cotcube-helpers/simple_output'
19
19
  require_relative 'cotcube-helpers/simple_series_stats'
20
20
  require_relative 'cotcube-helpers/input'
21
21
  require_relative 'cotcube-helpers/reduce'
22
+ require_relative 'cotcube-helpers/constants'
23
+ require_relative 'cotcube-helpers/symbols'
24
+ require_relative 'cotcube-helpers/init'
25
+ require_relative 'cotcube-helpers/get_id_set'
22
26
 
23
27
  module Cotcube
24
28
  module Helpers
@@ -26,7 +30,10 @@ module Cotcube
26
30
  :parallelize,
27
31
  :reduce,
28
32
  :simple_series_stats,
29
- :keystroke
33
+ :keystroke,
34
+ :symbols,
35
+ :get_id_set,
36
+ :init
30
37
 
31
38
  # please not that module_functions of source provided in private files must be published there
32
39
  end
@@ -29,28 +29,32 @@ class Array
29
29
  # This method iterates over an Array by calling the given block on all 2 consecutive elements
30
30
  # it returns a Array of self.size - 1
31
31
  #
32
- def pairwise(&block)
32
+ def pairwise(ret=nil, &block)
33
33
  raise ArgumentError, 'Array.one_by_one needs an arity of 2 (i.e. |a, b|)' unless block.arity == 2
34
+ raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' unless self.last.respond_to?(:[]=)
34
35
  return [] if size <= 1
35
36
 
36
- each_with_index.map do |_, i|
37
+ each_index.map do |i|
37
38
  next if i.zero?
38
39
 
39
- block.call(self[i - 1], self[i])
40
+ r = block.call(self[i - 1], self[i])
41
+ ret.nil? ? r : (self[i][ret] = r)
40
42
  end.compact
41
43
  end
42
44
 
43
45
  alias one_by_one pairwise
44
46
 
45
47
  # same as pairwise, but with arity of three
46
- def triplewise(&block)
48
+ def triplewise(ret=nil, &block)
47
49
  raise ArgumentError, 'Array.triplewise needs an arity of 3 (i.e. |a, b, c|)' unless block.arity == 3
50
+ raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' unless self.last.respond_to?(:[]=)
48
51
  return [] if size <= 2
49
52
 
50
- each_with_index.map do |_, i|
53
+ each_index.map do |i|
51
54
  next if i < 2
52
55
 
53
- block.call(self[i - 2], self[i - 1], self[i])
56
+ r = block.call(self[i - 2], self[i - 1], self[i])
57
+ ret.nil? ? r : (self[i][ret] = r)
54
58
  end.compact
55
59
  end
56
60
 
@@ -61,37 +65,37 @@ class Array
61
65
  unless attr.nil? || first[attr]
62
66
  raise ArgumentError,
63
67
  "At least first element of Array '#{first}' does not contain attr '#{attr}'!"
64
- end
65
- raise ArgumentError, 'Ranges should be an Array or, more precisely, respond_to :map' unless ranges.respond_to? :map
66
- raise ArgumentError, 'Each range in :ranges should respond to .include!' unless ranges.map do |x|
67
- x.respond_to? :include?
68
- end.reduce(:&)
69
-
70
- select do |el|
71
- value = attr.nil? ? el : el[attr]
72
- ranges.map do |range|
73
- range.include?(block.nil? ? value : block.call(value))
74
- end.reduce(:|)
75
- end
76
68
  end
69
+ raise ArgumentError, 'Ranges should be an Array or, more precisely, respond_to :map' unless ranges.respond_to? :map
70
+ raise ArgumentError, 'Each range in :ranges should respond to .include!' unless ranges.map do |x|
71
+ x.respond_to? :include?
72
+ end.reduce(:&)
73
+
74
+ select do |el|
75
+ value = attr.nil? ? el : el[attr]
76
+ ranges.map do |range|
77
+ range.include?(block.nil? ? value : block.call(value))
78
+ end.reduce(:|)
79
+ end
80
+ end
77
81
 
78
- def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
79
- # unless range.is_a? Range and
80
- # (range.begin.nil? or range.begin.is_a?(Integer)) and
81
- # (range.end.nil? or range.end.is_a?(Integer))
82
- # raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
83
- # end
82
+ def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
83
+ # unless range.is_a? Range and
84
+ # (range.begin.nil? or range.begin.is_a?(Integer)) and
85
+ # (range.end.nil? or range.end.is_a?(Integer))
86
+ # raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
87
+ # end
84
88
 
85
- raise ArgumentError, 'No block given.' unless block.is_a? Proc
89
+ raise ArgumentError, 'No block given.' unless block.is_a? Proc
86
90
 
87
- inclusive = true unless exclusive
88
- if inclusive && exclusive
89
- raise ArgumentError,
90
- "Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
91
- end
91
+ inclusive = true unless exclusive
92
+ if inclusive && exclusive
93
+ raise ArgumentError,
94
+ "Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
95
+ end
92
96
 
93
- index = find_index { |obj| block.call(obj) }
97
+ index = find_index { |obj| block.call(obj) }
94
98
 
95
- self[((inclusive ? index : index + 1)..)]
96
- end
99
+ self[((inclusive ? index : index + 1)..)]
100
+ end
97
101
  end
@@ -0,0 +1,34 @@
1
+
2
+ zen_string_literal: true
3
+
4
+ module Cotcube
5
+ module SwapSeeker
6
+ SYMBOL_EXAMPLES = [
7
+ { 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' },
8
+ { id: '209747', symbol: 'NM', ticksize: 0.25, power: 0.5, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'NASDAQ 100 MICRO' }
9
+ ].freeze
10
+
11
+ COLORS = %i[light_red light_yellow light_green red yellow green cyan magenta blue].freeze
12
+
13
+ MONTH_COLOURS = { 'F' => :cyan, 'G' => :green, 'H' => :light_green,
14
+ 'J' => :blue, 'K' => :yellow, 'M' => :light_yellow,
15
+ 'N' => :cyan, 'Q' => :magenta, 'U' => :light_magenta,
16
+ 'V' => :blue, 'X' => :red, 'Z' => :light_red }.freeze
17
+
18
+ MONTHS = { 'F' => 1, 'G' => 2, 'H' => 3,
19
+ 'J' => 4, 'K' => 5, 'M' => 6,
20
+ 'N' => 7, 'Q' => 8, 'U' => 9,
21
+ 'V' => 10, 'X' => 11, 'Z' => 12,
22
+ 1 => 'F', 2 => 'G', 3 => 'H',
23
+ 4 => 'J', 5 => 'K', 6 => 'M',
24
+ 7 => 'N', 8 => 'Q', 9 => 'U',
25
+ 10 => 'V', 11 => 'X', 12 => 'Z' }.freeze
26
+
27
+
28
+ CHICAGO = Time.find_zone('America/Chicago')
29
+
30
+ DATE_FMT = '%Y-%m-%d'
31
+
32
+ end
33
+ end
34
+
@@ -10,3 +10,33 @@ class DateTime
10
10
 
11
11
  alias to_sssm to_seconds_since_sunday_morning
12
12
  end
13
+
14
+ class Date
15
+
16
+ # creates a range of 2 dates, of the given calendar week, Monday to Sunday
17
+ def self.cw( week: , year: Date.today.year )
18
+ form = '%Y %W %w'
19
+ build_range = lambda {|w|
20
+ begin
21
+ ( DateTime.strptime("#{year} #{w} 1", form).to_date..
22
+ DateTime.strptime("#{year} #{w} 0", form).to_date)
23
+ rescue
24
+ # beyond Dec 31st #strptime must be called with cw:0 to keep it working
25
+ ( DateTime.strptime("#{year} #{w} 1", form).to_date..
26
+ DateTime.strptime("#{year+1} 0 0", form).to_date)
27
+ end
28
+ }
29
+ case week
30
+ when :current
31
+ build_range.call(Date.today.cweek)
32
+ when :last
33
+ wday = Date.today.wday
34
+ build_range.call((Date.today - (wday.zero? ? 7 : wday)).cweek)
35
+ when Integer
36
+ raise ArgumentError, "'#{week}' is not supported as calendar week, choose from (1..53)" if week <= 0 or week > 53
37
+ build_range.call(week)
38
+ else
39
+ raise ArgumentError, "'#{week}' is not a supported format for calendar week"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Helpers
5
+
6
+ def get_id_set(symbol: nil, id: nil, contract: nil, config: init)
7
+ contract = contract.to_s.upcase if contract.is_a? Symbol
8
+ id = id.to_s.upcase if id.is_a? Symbol
9
+ symbol = symbol.to_s.upcase if symbol.is_a? Symbol
10
+
11
+ if contract.is_a?(String) && (contract.length == 5)
12
+ c_symbol = contract[0..1]
13
+ if (not symbol.nil?) && (symbol != c_symbol)
14
+ raise ArgumentError,
15
+ "Mismatch between given symbol #{symbol} and contract #{contract}"
16
+ end
17
+
18
+ symbol = c_symbol
19
+ end
20
+
21
+ unless symbol.nil?
22
+ sym = symbols.select { |s| s[:symbol] == symbol.to_s.upcase }.first
23
+ if sym.nil? || sym[:id].nil?
24
+ raise ArgumentError,
25
+ "Could not find match in #{config[:symbols_file]} for given symbol #{symbol}"
26
+ end
27
+ raise ArgumentError, "Mismatching symbol #{symbol} and given id #{id}" if (not id.nil?) && (sym[:id] != id)
28
+
29
+ return sym
30
+ end
31
+ unless id.nil?
32
+ sym = symbols.select { |s| s[:id] == id.to_s }.first
33
+ if sym.nil? || sym[:id].nil?
34
+ raise ArgumentError,
35
+ "Could not find match in #{config[:symbols_file]} for given id #{id}"
36
+ end
37
+ return sym
38
+ end
39
+ raise ArgumentError, 'Need :id, :symbol or valid :contract '
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Helpers
5
+
6
+ def config_prefix
7
+ os = Gem::Platform.local.os
8
+ case os
9
+ when 'linux'
10
+ ''
11
+ when 'freebsd'
12
+ '/usr/local'
13
+ else
14
+ raise RuntimeError, "Unsupported architecture: #{os}"
15
+ end
16
+ end
17
+
18
+ def config_path
19
+ config_prefix + '/etc/cotcube'
20
+ end
21
+
22
+ def init(config_file_name: nil,
23
+ gem_name: nil,
24
+ debug: false)
25
+ gem_name ||= self.ancestors.first.to_s
26
+ config_file_name = "#{gem_name.down_case}.yml"
27
+ config_file = config_path + "/#{config_file_name}"
28
+
29
+ if File.exist?(config_file)
30
+ config = YAML.load(File.read config_file).transform_keys(&:to_sym)
31
+ else
32
+ config = {}
33
+ end
34
+
35
+ defaults = {
36
+ data_path: '/var/cotcube/' + name,
37
+ }
38
+
39
+ config = defaults.merge(config)
40
+ puts "CONFIG is '#{config}'" if debug
41
+
42
+ config
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ # Missing top level documentation
5
+ module Helpers
6
+
7
+ def symbols(config: init, type: nil, symbol: nil)
8
+ if config[:symbols_file].nil?
9
+ SYMBOL_EXAMPLES
10
+ else
11
+ CSV
12
+ .read(config[:symbols_file], headers: %i{ id symbol ticksize power months type bcf reports format name})
13
+ .map{|row| row.to_h }
14
+ .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row[:format] = "%#{row[:format]}f"; row }
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? }
18
+ end
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7.2
4
+ version: 0.1.9.1
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-02-01 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '13'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '13'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -82,9 +96,12 @@ files:
82
96
  - cotcube-helpers.gemspec
83
97
  - lib/cotcube-helpers.rb
84
98
  - lib/cotcube-helpers/array_ext.rb
99
+ - lib/cotcube-helpers/constants.rb
85
100
  - lib/cotcube-helpers/datetime_ext.rb
86
101
  - lib/cotcube-helpers/enum_ext.rb
102
+ - lib/cotcube-helpers/get_id_set.rb
87
103
  - lib/cotcube-helpers/hash_ext.rb
104
+ - lib/cotcube-helpers/init.rb
88
105
  - lib/cotcube-helpers/input.rb
89
106
  - lib/cotcube-helpers/parallelize.rb
90
107
  - lib/cotcube-helpers/range_ext.rb
@@ -96,6 +113,7 @@ files:
96
113
  - lib/cotcube-helpers/swig/date.rb
97
114
  - lib/cotcube-helpers/swig/fill_x.rb
98
115
  - lib/cotcube-helpers/swig/recognition.rb
116
+ - lib/cotcube-helpers/symbols.rb
99
117
  homepage: https://github.com/donkeybridge/cotcube-helpers
100
118
  licenses:
101
119
  - BSD-4-Clause