statsailr 0.7.5 → 0.7.6

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: 8701d54a846ae0d81c7f91080586c7dd81b05c081743ba84606c46ecc53f25a8
4
- data.tar.gz: 7f2636ea0b00008f160e303b389d977b94e7698a1eb800603850cff38901b14e
3
+ metadata.gz: 3404e4a53509861318d70a8309cf54fb82326f98d3715893ac3a1fe447eb94f5
4
+ data.tar.gz: cd48566b46c5ea5bdfd9fb38beb2381095f857b58ad1d0cbf2998ad5de4dded9
5
5
  SHA512:
6
- metadata.gz: 4007addec1d2a15f05c62bef40850a31648b4e2099ac7cf79890f0cb480854561990b478420bf3ab750089c88b1013b7fe4261c15738cb608b893257c2ef5134
7
- data.tar.gz: e38f0f64d035ab90bfdd8c052f63c1b4f0cd605cac841ddaefa18de6af127658f2c6453b4fbd74b7dfcf31e29920ba26c9b6db8b8211ee452ad983dce8c0ae3e
6
+ metadata.gz: f4ec746898a33f909803d6dbc4fc284818e3a65ba89c1e93199b0582c061e85ca6be472f77abdde9b9c9937bb43315e3ac8e9f4caa8e9d947b062c7c098c048d
7
+ data.tar.gz: ba926958960340cbd9ad2e278ef78841509ca2db771a1cab93def58b6b8eb305e7b40b29adb8410d8d48662c2e3568868183f739f89ce02937928f0f7d9a6010
@@ -0,0 +1,10 @@
1
+ class ProcBlockFinalizer
2
+ attr :enabled, true
3
+ def initialize
4
+ @enabled = false
5
+ end
6
+
7
+ def enabled?
8
+ return @enabled
9
+ end
10
+ end
@@ -18,7 +18,7 @@ class ProcOptValidator
18
18
  raise "#{opt_name} is required for this PROC option"
19
19
  end
20
20
  end
21
- if ! validator["is_a"].nil?
21
+ if ! param_manager.param_hash[opt_name].nil? && ! validator["is_a"].nil?
22
22
  if validator["is_a"].is_a?(Array)
23
23
  if ! validator["is_a"].include? class_name_in_param_manager
24
24
  raise "#{opt_name} needs to be one of #{validator["is_a"].join("|")}, but #{class_name_in_param_manager} is assigned"
@@ -30,7 +30,7 @@ class ProcOptValidator
30
30
  end
31
31
 
32
32
  end
33
- if ! validator["as"].nil?
33
+ if ! param_manager.param_hash[opt_name].nil? && ! validator["as"].nil?
34
34
  if validator["as"] != class_name_in_param_manager
35
35
  case validator["as"]
36
36
  when "SymbolR"
@@ -1,10 +1,12 @@
1
1
  require "pathname"
2
2
  require_relative("./proc_opt_validator.rb")
3
+ require_relative("./proc_block_finalizer.rb")
3
4
 
4
5
  module ProcSettingModule
5
6
  def self.included base
6
7
  base.extend ClassMethods
7
8
  base.instance_variable_set(:@validator, ProcOptValidator.new())
9
+ base.instance_variable_set(:@finalizer, ProcBlockFinalizer.new())
8
10
  base.send :include, InstanceMethods
9
11
  end
10
12
 
@@ -12,6 +14,8 @@ module ProcSettingModule
12
14
  def extend_object( extender )
13
15
  extender.instance_variable_set(:@validator, @validator)
14
16
  extender.singleton_class.__send__( :attr_accessor, :validator)
17
+ extender.instance_variable_set(:@finalizer, @finalizer)
18
+ extender.singleton_class.__send__( :attr_accessor, :finalizer)
15
19
  super
16
20
  end
17
21
 
@@ -36,6 +40,14 @@ module ProcSettingModule
36
40
  def validator
37
41
  @validator
38
42
  end
43
+
44
+ def finalizer_enabled
45
+ @finalizer.enabled = true
46
+ end
47
+
48
+ def finalizer
49
+ @finalizer
50
+ end
39
51
  end
40
52
 
41
53
  module InstanceMethods
@@ -69,6 +69,8 @@ require_relative("proc_setting_support/proc_setting_module.rb")
69
69
 
70
70
  module ProcBlockToR
71
71
  include BlockToRSupport
72
+ FINALIZER_NAME = "finalizer"
73
+
72
74
  def self.create_lazy_funcs( blk , proc_setting_manager )
73
75
  proc_command = blk.command
74
76
  param_manager = RBridge::RParamManager.new( blk.opts )
@@ -90,6 +92,13 @@ module ProcBlockToR
90
92
  proc_lazy_funcs_with_print_result_opts = proc_stmts.map(){|proc_stmt|
91
93
  lzf_gen.gen_lazy_func( proc_command, proc_stmt, param_manager )
92
94
  }
95
+
96
+ finalizer = lzf_gen.finalizer
97
+ if finalizer.enabled?
98
+ finalizer_func = lzf_gen.gen_lazy_func( proc_command , [ FINALIZER_NAME, "", nil] , param_manager )
99
+ proc_lazy_funcs_with_print_result_opts.push( finalizer_func )
100
+ end
101
+
93
102
  return proc_lazy_funcs_with_print_result_opts
94
103
  end
95
104
  end
@@ -84,6 +84,88 @@ module LazyFuncGeneratorSettingUtility
84
84
  return RBridge.create_strvec( result_ary )
85
85
  end
86
86
 
87
+ def read_named_args_as_named_strvec(ary)
88
+ arg_num_ary = Array.new( ary.size )
89
+ deapth_ary = Array.new( ary.size )
90
+ idx = 0
91
+ last_idx = ary.size - 1
92
+ arg_num = nil
93
+ deapth = nil
94
+
95
+ while( idx <= last_idx )
96
+ if( idx == 0 )
97
+ # name starts
98
+ unless ( deapth.nil? && ary[idx].is_a?(RBridge::SymbolR) && (ary[idx + 1].is_a?(RBridge::SignR) && ary[idx + 1].to_s == "="))
99
+ raise "read_named_args_as_named_strvec requires an argument to start with name=expr"
100
+ end
101
+ arg_num = 0
102
+ deapth = 0
103
+ elsif( deapth == 0 && ary[idx].is_a?(RBridge::SymbolR) && (ary[idx + 1].is_a?(RBridge::SignR) && ary[idx + 1].to_s == "="))
104
+ # name starts
105
+ arg_num = arg_num + 1
106
+ elsif( ary[idx].is_a?(RBridge::SymbolR) && (ary[idx + 1].is_a?(RBridge::SignR) && ary[idx + 1].to_s == "("))
107
+ # function starts
108
+ deapth_ary[idx] = deapth
109
+ arg_num_ary[idx] = arg_num
110
+ deapth = deapth + 1
111
+ idx = idx + 1
112
+ deapth_ary[idx] = deapth
113
+ elsif( ary[idx].is_a?(RBridge::SignR) && ary[idx].to_s == "(")
114
+ # parenthesis starts
115
+ deapth = deapth + 1
116
+ deapth_ary[idx] = deapth
117
+ elsif( ary[idx].is_a?(RBridge::SignR) && ary[idx].to_s == ")")
118
+ # parenthesis ends or function ends
119
+ deapth_ary[idx] = deapth
120
+ deapth = deapth - 1
121
+ else
122
+ deapth_ary[idx] = deapth
123
+ end
124
+ arg_num_ary[idx] = arg_num
125
+ idx = idx + 1
126
+ end
127
+
128
+ result_ary = []
129
+ name_ary = []
130
+ prev_arg_num = -1
131
+ idx = 0
132
+ elem_arg_num_ary = ary.zip( arg_num_ary )
133
+ while( idx < elem_arg_num_ary.size )
134
+ elem = ary[idx]
135
+ arg_num = arg_num_ary[idx]
136
+ if elem.respond_to? :to_s_for_r_parsing
137
+ elem_str = elem.to_s_for_r_parsing
138
+ else
139
+ elem_str = elem.to_s
140
+ end
141
+
142
+ if( arg_num != prev_arg_num ) # starts new 'name=expr'
143
+ name_ary.push elem_str
144
+ idx = idx + 1
145
+ if( ary[idx].to_s != "=" )
146
+ raise "An argument should be in the form of 'name=expr'"
147
+ end
148
+ else
149
+ if( result_ary[arg_num].nil? )
150
+ unless result_ary.size == arg_num
151
+ raise "arg_num is not an appropriate number."
152
+ end
153
+ result_ary[arg_num] = [elem_str]
154
+ else
155
+ result_ary[arg_num].push( elem_str )
156
+ end
157
+ end
158
+ idx = idx + 1
159
+ prev_arg_num = arg_num
160
+ end
161
+
162
+ result_vec = RBridge.create_strvec( result_ary.map(){|ary| ary.join(" ") } )
163
+ name_vec = RBridge.create_strvec( name_ary )
164
+ add_name_func = RBridge.create_ns_function_call("stats", "setNames", {"object" => result_vec, "nm" => name_vec })
165
+ result_name_vec = RBridge.exec_function( add_name_func )
166
+ return result_name_vec
167
+ end
168
+
87
169
  def result( name , *addl )
88
170
  if addl.empty?
89
171
  return RBridge::RResultName.new(name)
@@ -103,6 +185,10 @@ module LazyFuncGeneratorSettingUtility
103
185
  return RBridge::RResultPrevious.new( default_obj )
104
186
  end
105
187
 
188
+ def previous_inst_name()
189
+ return RBridge::RInstPrevious.new()
190
+ end
191
+
106
192
  def r_obj( val )
107
193
  return RBridge.convert_to_r_object( val )
108
194
  end
@@ -1,3 +1,3 @@
1
1
  module StatSailr
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsailr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshihiro Umehara
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-19 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r_bridge
@@ -84,6 +84,7 @@ files:
84
84
  - lib/statsailr.rb
85
85
  - lib/statsailr/block_builder/sts_block.rb
86
86
  - lib/statsailr/block_builder/sts_block_parse_proc_opts.rb
87
+ - lib/statsailr/block_to_r/proc_setting_support/proc_block_finalizer.rb
87
88
  - lib/statsailr/block_to_r/proc_setting_support/proc_opt_validator.rb
88
89
  - lib/statsailr/block_to_r/proc_setting_support/proc_setting_manager.rb
89
90
  - lib/statsailr/block_to_r/proc_setting_support/proc_setting_module.rb
@@ -111,7 +112,7 @@ metadata:
111
112
  homepage_uri: https://github.com/niceume/statsailr
112
113
  source_code_uri: https://github.com/niceume/statsailr
113
114
  changelog_uri: https://github.com/niceume/statsailr
114
- post_install_message:
115
+ post_install_message:
115
116
  rdoc_options: []
116
117
  require_paths:
117
118
  - lib
@@ -126,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  - !ruby/object:Gem::Version
127
128
  version: '0'
128
129
  requirements: []
129
- rubygems_version: 3.1.4
130
- signing_key:
130
+ rubygems_version: 3.2.31
131
+ signing_key:
131
132
  specification_version: 4
132
133
  summary: Provides a platform to focus on statistics
133
134
  test_files: []