cotcube-helpers 0.1.7.1 → 0.1.9

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: c53dd160cd7774a8808b28681dd7ad363cb46f7b69ae402d89c190e531060837
4
- data.tar.gz: 0f0731c06b715e753c73685f7acc967881b616410edde425705f43c38df601fc
3
+ metadata.gz: 1b44c8314e88c5aca5675c78b3295f082730ddce80afc445d80228260e5c566e
4
+ data.tar.gz: 1bb545d175194aa375675b715ac63defbc1bef7101d828197d3d2aac6456cc4f
5
5
  SHA512:
6
- metadata.gz: 3920e5754a1b8ae41f8d0ebe83502d9935766b08da022367694fe0ed4591e7c759378a8badca27e0672851fb7599ad97ceff1986146add4285ce4386d8e5852a
7
- data.tar.gz: 419275382240a93ad604cb32208b57e1b9e3cbf9db95bd0853b80b0fe4a29c10d162af2a20d801c5cb19fd04296d6519b442d66786e5bc56d82ee4f0da37b841
6
+ metadata.gz: 1bf9097c6a01afb4d68bb4bf884d7766fad12481f585ee8df9a6def9fbc82b0cef5ce0fa98eeaaad65d682406d9ac11bae8993f760a60ae390cea23aceeba791
7
+ data.tar.gz: 1f987e28e73bc9cbb66da5f8d51f7d0c4200f03c683ee36dc7f228b3684149b33aa6ed9d2d490ace172e5c8811d1f344e427324449066a2621fca55394556e67
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.1.9 (May 07, 2021)
2
+ - added constants, init and symbols to helpers
3
+
4
+ ## 0.1.8 (April 18, 2021)
5
+ - datetime_ext: Date.cw provides a range of (Date..Date) representing the according calendar week
6
+
7
+ ## 0.1.7.4 (March 13, 2021)
8
+ - hotfix on 0.1.7.3
9
+
10
+ ## 0.1.7.3 (March 13, 2021)
11
+ - array_ext: pairwise and triplewise now support saving result in latter members []=
12
+
13
+ ## 0.1.7.2 (February 01, 2021)
14
+ - adding #deep_freeze to Enumerable
15
+ - range_ext: added #mod to modify an (actually) immutable range
16
+ - simple_series_stats: minor fix
17
+
1
18
  ## 0.1.7.1 (January 17, 2021)
2
19
  - bugfix
3
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7.1
1
+ 0.1.9
@@ -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,9 @@ 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-heleprs/init'
22
25
 
23
26
  module Cotcube
24
27
  module Helpers
@@ -26,7 +29,9 @@ module Cotcube
26
29
  :parallelize,
27
30
  :reduce,
28
31
  :simple_series_stats,
29
- :keystroke
32
+ :keystroke,
33
+ :symbols,
34
+ :init
30
35
 
31
36
  # please not that module_functions of source provided in private files must be published there
32
37
  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
@@ -11,3 +11,25 @@ class Enumerator
11
11
  ret
12
12
  end
13
13
  end
14
+
15
+ # Recursively freeze self if it's Enumerable
16
+ # Supports all Ruby versions 1.8.* to 2.2.*+
17
+ module Kernel
18
+ alias deep_freeze freeze
19
+ alias deep_frozen? frozen?
20
+ end
21
+
22
+ # Adding deep_freeze and deep_frozen?
23
+ module Enumerable
24
+ def deep_freeze
25
+ unless @deep_frozen
26
+ each(&:deep_freeze)
27
+ @deep_frozen = true
28
+ end
29
+ freeze
30
+ end
31
+
32
+ def deep_frozen?
33
+ !!@deep_frozen
34
+ end
35
+ end
@@ -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
+
@@ -2,6 +2,10 @@
2
2
 
3
3
  # Monkey patching the Ruby Core class Range
4
4
  class Range
5
+ def mod(first, last = 0)
6
+ exclude_end? ? ((self.begin + first)...(self.end + last)) : ((self.begin + first)..(self.begin + last))
7
+ end
8
+
5
9
  def to_time_intervals(step:,
6
10
  timezone: Time.find_zone('America/Chicago'),
7
11
  # ranges: nil,
@@ -23,9 +23,7 @@ module Cotcube
23
23
  sort
24
24
  unless dim.zero?
25
25
  reductor = (base.size * dim).round
26
- puts reductor
27
26
  worker = worker[reductor..base.size - reductor]
28
- puts worker.size
29
27
  end
30
28
  result = {}
31
29
 
@@ -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.1
4
+ version: 0.1.9
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-01-17 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,11 @@ 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
87
102
  - lib/cotcube-helpers/hash_ext.rb
103
+ - lib/cotcube-helpers/init.rb
88
104
  - lib/cotcube-helpers/input.rb
89
105
  - lib/cotcube-helpers/parallelize.rb
90
106
  - lib/cotcube-helpers/range_ext.rb
@@ -96,6 +112,7 @@ files:
96
112
  - lib/cotcube-helpers/swig/date.rb
97
113
  - lib/cotcube-helpers/swig/fill_x.rb
98
114
  - lib/cotcube-helpers/swig/recognition.rb
115
+ - lib/cotcube-helpers/symbols.rb
99
116
  homepage: https://github.com/donkeybridge/cotcube-helpers
100
117
  licenses:
101
118
  - BSD-4-Clause