tbpgr_utils 0.0.83 → 0.0.84

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.
data/README.md CHANGED
@@ -75,8 +75,9 @@ Or install it yourself as:
75
75
  |[EvalHelper#unless_code](#evalhelperunless_code) |create unless strings, for eval |
76
76
  |[EvalHelper#unless_code_after](#evalhelperunless_code_after) |create after-unless strings, for eval |
77
77
  |[TbpgrUtils File.insert_bom](#fileinsert_bom) |insert BOM to UTF-8 File |
78
+ |[TbpgrUtils Fixnum to_fixnum_table](#fixnum-to_fixnum_table) |return value is fixnum table |
78
79
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
79
- |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
80
+ |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
80
81
  |[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
81
82
  |[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
82
83
  |[TestToolbox Kernel#capture_stdout](#kernelcapture_stdout) |capture STDOUT |
@@ -1179,6 +1180,42 @@ File.insert_bom("input.csv") # => output bommed text to output.csv
1179
1180
 
1180
1181
  [back to list](#list)
1181
1182
 
1183
+ ### Fixnum.to_fixnum_table
1184
+ 1 to 100 by 10 case
1185
+ ~~~ruby
1186
+ Fixnum.to_fixnum_table(1, 100, 10)
1187
+ ~~~
1188
+
1189
+ result
1190
+ ~~~
1191
+ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
1192
+ |11|12|13|14|15|16|17|18|19| 20|
1193
+ |21|22|23|24|25|26|27|28|29| 30|
1194
+ |31|32|33|34|35|36|37|38|39| 40|
1195
+ |41|42|43|44|45|46|47|48|49| 50|
1196
+ |51|52|53|54|55|56|57|58|59| 60|
1197
+ |61|62|63|64|65|66|67|68|69| 70|
1198
+ |71|72|73|74|75|76|77|78|79| 80|
1199
+ |81|82|83|84|85|86|87|88|89| 90|
1200
+ |91|92|93|94|95|96|97|98|99|100|
1201
+ ~~~
1202
+
1203
+ 1 to 10 by 2 case
1204
+ ~~~ruby
1205
+ Fixnum.to_fixnum_table(1, 10, 2)
1206
+ ~~~
1207
+
1208
+ result
1209
+ ~~~
1210
+ |1| 2|
1211
+ |3| 4|
1212
+ |5| 6|
1213
+ |7| 8|
1214
+ |9|10|
1215
+ ~~~
1216
+
1217
+ [back to list](#list)
1218
+
1182
1219
  ### Ghostable
1183
1220
  * include Ghostable
1184
1221
  * create ghost method by using Ghostable::ghost_method
@@ -2843,6 +2880,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
2843
2880
  https://github.com/tbpgr/tbpgr_utils_snippets
2844
2881
 
2845
2882
  ## History
2883
+ * version 0.0.84 : add Fixnum to_fixnum_table
2846
2884
  * version 0.0.83 : add Numeric to_digit_table
2847
2885
  * version 0.0.82 : add Numeric to_oct_table
2848
2886
  * version 0.0.81 : add Numeric to_hex_table
@@ -13,11 +13,11 @@ class Array
13
13
  # |header1|header2|header3|
14
14
  # |line1_1|line1_2|line1_3|
15
15
  #
16
- def to_table
16
+ def to_table(position = :right)
17
17
  ret = reduce([]) do |rets, lines|
18
18
  ret = lines.reduce([]) { |ret, column|ret << column; ret }
19
19
  rets << "|#{ret.join("|")}|"
20
20
  end.join("\n") + "\n"
21
- ret.justify_table(:center)
21
+ ret.justify_table(position)
22
22
  end
23
23
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'open_classes/array/to_table'
3
+
4
+ # Fixnum
5
+ class Fixnum
6
+ # return value is fixnum table
7
+ #
8
+ # ==== Examples
9
+ #
10
+ # 1 to 100 by 10 case
11
+ #
12
+ # Fixnum.to_fixnum_table(1, 100, 10)
13
+ #
14
+ # result
15
+ #
16
+ # | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
17
+ # |11|12|13|14|15|16|17|18|19| 20|
18
+ # |21|22|23|24|25|26|27|28|29| 30|
19
+ # |31|32|33|34|35|36|37|38|39| 40|
20
+ # |41|42|43|44|45|46|47|48|49| 50|
21
+ # |51|52|53|54|55|56|57|58|59| 60|
22
+ # |61|62|63|64|65|66|67|68|69| 70|
23
+ # |71|72|73|74|75|76|77|78|79| 80|
24
+ # |81|82|83|84|85|86|87|88|89| 90|
25
+ # |91|92|93|94|95|96|97|98|99|100|
26
+ #
27
+ # 1 to 10 by 2 case
28
+ #
29
+ # Fixnum.to_fixnum_table(1, 10, 2)
30
+ #
31
+ # result
32
+ #
33
+ # |1| 2|
34
+ # |3| 4|
35
+ # |5| 6|
36
+ # |7| 8|
37
+ # |9|10|
38
+ #
39
+ def self.to_fixnum_table(from = 1, to = 100, return_num = 10)
40
+ return '' unless from.is_a?(Fixnum)
41
+ return '' unless to.is_a?(Fixnum)
42
+ [*from..to].each_slice(return_num).to_a.to_table
43
+ end
44
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'open_classes/fixnum/to_fixnum_table'
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'open_classes/string/ascii1_other2_size'
2
3
 
3
4
  # String
4
5
  class String
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.83'
5
+ VERSION = '0.0.84'
6
6
  end
data/lib/tbpgr_utils.rb CHANGED
@@ -5,6 +5,7 @@ require 'tbpgr_utils/version'
5
5
  module TbpgrUtils
6
6
  require 'open_classes/array'
7
7
  require 'open_classes/file'
8
+ require 'open_classes/fixnum'
8
9
  require 'open_classes/hash'
9
10
  require 'open_classes/kernel'
10
11
  require 'open_classes/module'
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'open_classes/fixnum/to_fixnum_table'
4
+
5
+ describe Fixnum do
6
+ context :to_fixnum_table do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: '1-100 case',
11
+ from: 1,
12
+ to: 100,
13
+ by: 10,
14
+ expected: <<-EOS
15
+ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
16
+ |11|12|13|14|15|16|17|18|19| 20|
17
+ |21|22|23|24|25|26|27|28|29| 30|
18
+ |31|32|33|34|35|36|37|38|39| 40|
19
+ |41|42|43|44|45|46|47|48|49| 50|
20
+ |51|52|53|54|55|56|57|58|59| 60|
21
+ |61|62|63|64|65|66|67|68|69| 70|
22
+ |71|72|73|74|75|76|77|78|79| 80|
23
+ |81|82|83|84|85|86|87|88|89| 90|
24
+ |91|92|93|94|95|96|97|98|99|100|
25
+ EOS
26
+ },
27
+ {
28
+ case_no: 2,
29
+ case_title: '1-10, by2 case',
30
+ from: 1,
31
+ to: 10,
32
+ by: 2,
33
+ expected: <<-EOS
34
+ |1| 2|
35
+ |3| 4|
36
+ |5| 6|
37
+ |7| 8|
38
+ |9|10|
39
+ EOS
40
+ },
41
+ {
42
+ case_no: 3,
43
+ case_title: 'from is not Fixnum case',
44
+ from: '1',
45
+ to: 10,
46
+ by: 2,
47
+ expected: ''
48
+ },
49
+ {
50
+ case_no: 4,
51
+ case_title: 'to is not Fixnum case',
52
+ from: 1,
53
+ to: '10',
54
+ by: 2,
55
+ expected: ''
56
+ },
57
+ ]
58
+
59
+ cases.each do |c|
60
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
61
+ begin
62
+ case_before c
63
+
64
+ # -- given --
65
+ # nothing
66
+
67
+ # -- when --
68
+ actual = Fixnum.to_fixnum_table(c[:from], c[:to], c[:by])
69
+
70
+ # -- then --
71
+ expect(actual).to eq(c[:expected])
72
+ ensure
73
+ case_after c
74
+ end
75
+ end
76
+
77
+ def case_before(c)
78
+ # implement each case before
79
+ end
80
+
81
+ def case_after(c)
82
+ # implement each case after
83
+ end
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.83
4
+ version: 0.0.84
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &27713340 !ruby/object:Gem::Requirement
16
+ requirement: &20525976 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *27713340
24
+ version_requirements: *20525976
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &27711936 !ruby/object:Gem::Requirement
27
+ requirement: &20525688 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *27711936
35
+ version_requirements: *20525688
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &27711564 !ruby/object:Gem::Requirement
38
+ requirement: &20525460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *27711564
46
+ version_requirements: *20525460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &27710748 !ruby/object:Gem::Requirement
49
+ requirement: &20525136 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.14.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *27710748
57
+ version_requirements: *20525136
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &27709200 !ruby/object:Gem::Requirement
60
+ requirement: &20524836 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *27709200
68
+ version_requirements: *20524836
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -134,6 +134,8 @@ files:
134
134
  - lib/open_classes/array/together_slice.rb
135
135
  - lib/open_classes/array/together_with_index.rb
136
136
  - lib/open_classes/file.rb
137
+ - lib/open_classes/fixnum.rb
138
+ - lib/open_classes/fixnum/to_fixnum_table.rb
137
139
  - lib/open_classes/hash.rb
138
140
  - lib/open_classes/hash/table.rb
139
141
  - lib/open_classes/kernel.rb
@@ -232,6 +234,7 @@ files:
232
234
  - spec/open_classes/array/together_spec.rb
233
235
  - spec/open_classes/array/together_with_index_spec.rb
234
236
  - spec/open_classes/file_spec.rb
237
+ - spec/open_classes/fixnum/to_fixnum_table_spec.rb
235
238
  - spec/open_classes/hash/table_spec.rb
236
239
  - spec/open_classes/kernel/aa_ancestors_spec.rb
237
240
  - spec/open_classes/kernel/booleans_spec.rb
@@ -350,6 +353,7 @@ test_files:
350
353
  - spec/open_classes/array/together_spec.rb
351
354
  - spec/open_classes/array/together_with_index_spec.rb
352
355
  - spec/open_classes/file_spec.rb
356
+ - spec/open_classes/fixnum/to_fixnum_table_spec.rb
353
357
  - spec/open_classes/hash/table_spec.rb
354
358
  - spec/open_classes/kernel/aa_ancestors_spec.rb
355
359
  - spec/open_classes/kernel/booleans_spec.rb