s_matrix 0.0.1 → 0.0.3

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.
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'xml_load'
3
+
4
+ describe SMatrix do
5
+ describe 'test id' do
6
+ it '' do
7
+ #获得当前执行文件的完整路径
8
+ plist_path = Pathname.new(File.dirname(__FILE__)).realpath.to_s
9
+
10
+ GC.start
11
+ p 'before load to const'
12
+ puts `ps aux | grep ruby | grep spec`
13
+ p ''
14
+ Const.load_to_const_with_keys('EQUIPMENT_STRENGTHEN', [:equipment_id, :level], plist_path + '/equipment_strengthen.plist')
15
+ GC.start
16
+ p 'after load to const'
17
+ puts `ps aux | grep ruby | grep spec`
18
+ p ''
19
+
20
+
21
+ a = SMatrix.new
22
+ Const::EQUIPMENT_STRENGTHEN.each do |equip_id, hash_with_lev|
23
+ hash_with_lev.each do |lev, info|
24
+ a.add_row("#{equip_id}:#{lev}", info)
25
+ end
26
+ end
27
+
28
+ GC.start
29
+ p 'after load_to_s_matix after GC'
30
+ puts `ps aux | grep ruby | grep spec`
31
+ p ''
32
+
33
+
34
+ EQUIP = a
35
+ GC.start
36
+ p 'after set a const to smatix'
37
+ puts `ps aux | grep ruby | grep spec`
38
+ p ''
39
+
40
+ p 'size of smatix'
41
+ puts a.size
42
+
43
+ #puts EQUIP.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe SMatrix do
4
+ describe 'test id' do
5
+ it '' do
6
+ a = SMatrix.new
7
+ expect(a.add_row('2', {'a' => '2'})).to eq(a)
8
+ expect(a.add_row(2, {a: 2})).to eq(a)
9
+ expect(a.add_row(:symbel_is_ok, {a: 2})).to eq(a)
10
+
11
+ expect {a.add_row('', {a: 2})}.to raise_error
12
+ expect {a.add_row(nil, {a: 2})}.to raise_error
13
+ end
14
+ end
15
+
16
+ describe 'test row' do
17
+ it '' do
18
+ a = SMatrix.new
19
+ expect {a.add_row('222', 1)}.to raise_error
20
+ expect {a.add_row('222', [1, 2])}.to raise_error
21
+ end
22
+ end
23
+
24
+ describe 'test to_s' do
25
+ it '' do
26
+ a = SMatrix.new
27
+ puts a.to_s
28
+ a.add_row(2, {a: 2})
29
+ puts a.to_s
30
+ end
31
+ end
32
+
33
+ describe 'test add and get' do
34
+ it '' do
35
+ a = SMatrix.new
36
+ expect(a.add_row('2', {a: 2})).to eq(a)
37
+ rst = a.get_row('2')
38
+ expect(a.get_row('2')).to eq({'a' => '2'})
39
+ end
40
+
41
+ it '' do
42
+ a = SMatrix.new
43
+ a.add_row('2', {a: 2})
44
+ a.add_row('3', {b: 3})
45
+
46
+ expect(a.get_row('2')).to eq({'a' => '2', 'b' => nil})
47
+ expect(a.get_row('3')).to eq({'a' => nil, 'b' => '3'})
48
+
49
+ a.add_row('4', {a: 4, c: 5})
50
+ expect(a.get_row('2')).to eq({'a' => '2', 'b' => nil, 'c' => nil})
51
+ expect(a.get_row('3')).to eq({'a' => nil, 'b' => '3', 'c' => nil})
52
+ expect(a.get_row('4')).to eq({'a' => '4', 'b' => nil, 'c' => '5'})
53
+
54
+ end
55
+
56
+ it '' do
57
+ a = SMatrix.new
58
+ a.add_row('2', {a: 2})
59
+ a.add_row('2', {b: 3})
60
+ expect(a.get_row('2')).to eq({'a' => nil, 'b' => '3'})
61
+ end
62
+ end
63
+
64
+ describe 'each' do
65
+ it '' do
66
+ a = SMatrix.new
67
+ a.add_row('2', {a: 2})
68
+ a.add_row('3', {b: 3})
69
+
70
+ # must 2 params with block
71
+ #expect { a.each }.to raise_error
72
+ #expect { a.each {|a|} }.to raise_error
73
+ #expect { a.each {|a, b, c|} }.to raise_error
74
+
75
+
76
+ # key and value is right
77
+ hash = {}
78
+ a.each do |k, v|
79
+ hash[k] = v
80
+ end
81
+ expect(hash).to eq({
82
+ '2' => {'a' => '2', 'b' => nil},
83
+ '3' => {'a' => nil, 'b' => '3'}
84
+ })
85
+ end
86
+ end
87
+
88
+
89
+ end
90
+
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 's_matrix' # and any other gems you need
5
+ require 'plist'
6
+ require 'pathname'
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
data/spec/xml_load.rb ADDED
@@ -0,0 +1,55 @@
1
+ #require ‘pathname’
2
+
3
+
4
+ module Const
5
+ def self.load_to_const_with_keys(const_string, keys, file)
6
+ content_array = Plist.parse_xml(file)
7
+ const_hash = {}
8
+
9
+ case keys.size
10
+ when 1
11
+ content_array.each {|content|
12
+ key = str_to_key(content[keys[0].to_s])
13
+ const_hash[key] = data_type_conversion(content)
14
+ }
15
+
16
+ when 2
17
+ content_array.each {|content|
18
+ key0 = str_to_key(content[keys[0].to_s])
19
+ key1 = str_to_key(content[keys[1].to_s])
20
+
21
+ const_hash[key0] = {} if const_hash[key0].nil?
22
+ const_hash[key0][key1] = data_type_conversion(content)
23
+ }
24
+
25
+ else
26
+ raise 'not support more than 3 indexes currently'
27
+ end
28
+ result = const_hash
29
+ Const.const_set(const_string, result)
30
+ end
31
+
32
+ def self.str_to_key(str)
33
+ is_number?(str) ? str.to_i : str.strip.to_sym
34
+ end
35
+
36
+ def self.is_number?(str)
37
+ str.to_i.to_s == str
38
+ end
39
+
40
+ def self.data_type_conversion(hash)
41
+ tmp_result = {}
42
+ hash.each do |k, v|
43
+ tmp_result[k.to_sym] = v
44
+ next unless v.kind_of?(String)
45
+ tmp_result[k.to_sym] = v.strip
46
+
47
+ i_number = v.to_i
48
+ str = v.strip
49
+ next tmp_result[k.to_sym] = i_number if i_number.to_s == str
50
+ f_number = v.to_f
51
+ next tmp_result[k.to_sym] = f_number if f_number.to_s == str
52
+ end
53
+ tmp_result
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhangyuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,24 +30,91 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: plist
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
41
83
  description: not finish
42
84
  email:
43
85
  - libinzhangyuan@gmail.com
44
86
  executables: []
45
- extensions: []
87
+ extensions:
88
+ - ext/s_matrix/extconf.rb
46
89
  extra_rdoc_files: []
47
90
  files:
48
91
  - ".gitignore"
92
+ - Gemfile
49
93
  - LICENSE
50
94
  - README.md
95
+ - Rakefile
96
+ - ext/s_matrix/Makefile
97
+ - ext/s_matrix/extconf.rb
98
+ - ext/s_matrix/gmatx.cpp
99
+ - ext/s_matrix/gmatx.h
100
+ - ext/s_matrix/matx_content.cpp
101
+ - ext/s_matrix/matx_content.h
102
+ - ext/s_matrix/matx_row.cpp
103
+ - ext/s_matrix/matx_row.h
104
+ - ext/s_matrix/matx_string.h
105
+ - ext/s_matrix/matx_title.cpp
106
+ - ext/s_matrix/matx_title.h
107
+ - ext/s_matrix/matx_type_def.h
108
+ - ext/s_matrix/mkmf.log
109
+ - ext/s_matrix/s_matrix.cpp
110
+ - lib/s_matrix.rb
111
+ - lib/s_matrix/version.rb
112
+ - s_matrix.gemspec
113
+ - spec/equipment_strengthen.plist
114
+ - spec/performance_spec.rb
115
+ - spec/smatrix_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/xml_load.rb
51
118
  homepage: https://github.com/libinzhangyuan/s_matrix
52
119
  licenses:
53
120
  - MIT
@@ -73,4 +140,9 @@ signing_key:
73
140
  specification_version: 4
74
141
  summary: educe memory usage for a large number of config. for example game config
75
142
  in excel.
76
- test_files: []
143
+ test_files:
144
+ - spec/equipment_strengthen.plist
145
+ - spec/performance_spec.rb
146
+ - spec/smatrix_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/xml_load.rb