tbpgr_utils 0.0.91 → 0.0.92

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -77,7 +77,8 @@ Or install it yourself as:
77
77
  |[EvalHelper#unless_code_after](#evalhelperunless_code_after) |create after-unless strings, for eval |
78
78
  |[Familyable](#familyable) |user family model(family, person, parents, children, brothers) |
79
79
  |[TbpgrUtils File.insert_bom](#fileinsert_bom) |insert BOM to UTF-8 File |
80
- |[TbpgrUtils Fixnum to_fixnum_table](#fixnum-to_fixnum_table) |return value is fixnum table |
80
+ |[TbpgrUtils Fixnum to_fixnum_html_table](#fixnum-to_fixnum_html_table) |return value is fixnum html table |
81
+ |[TbpgrUtils Fixnum to_fixnum_table](#fixnumto_fixnum_table) |return value is fixnum table |
81
82
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
82
83
  |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
83
84
  |[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
@@ -1256,6 +1257,41 @@ File.insert_bom("input.csv") # => output bommed text to output.csv
1256
1257
 
1257
1258
  [back to list](#list)
1258
1259
 
1260
+ ### Fixnum.to_fixnum_html_table
1261
+ 1 to 10 by 2 case
1262
+ ~~~ruby
1263
+ require 'tbpgr_utils'
1264
+ Fixnum.to_fixnum_html_table(1, 10, 2)
1265
+ ~~~
1266
+
1267
+ result
1268
+ ~~~
1269
+ <table>
1270
+ <tr>
1271
+ <td>1</td>
1272
+ <td>2</td>
1273
+ </tr>
1274
+ <tr>
1275
+ <td>3</td>
1276
+ <td>4</td>
1277
+ </tr>
1278
+ <tr>
1279
+ <td>5</td>
1280
+ <td>6</td>
1281
+ </tr>
1282
+ <tr>
1283
+ <td>7</td>
1284
+ <td>8</td>
1285
+ </tr>
1286
+ <tr>
1287
+ <td>9</td>
1288
+ <td>10</td>
1289
+ </tr>
1290
+ </table>
1291
+ ~~~
1292
+
1293
+ [back to list](#list)
1294
+
1259
1295
  ### Fixnum.to_fixnum_table
1260
1296
  1 to 100 by 10 case
1261
1297
  ~~~ruby
@@ -3020,6 +3056,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3020
3056
  https://github.com/tbpgr/tbpgr_utils_snippets
3021
3057
 
3022
3058
  ## History
3059
+ * version 0.0.92 : add Fixnum.to_fixnum_html_table
3023
3060
  * version 0.0.91 : add Array#to_html_table
3024
3061
  * version 0.0.90 : add Kernel#hash_to_attributes
3025
3062
  * version 0.0.89 : add String#escape_quote
@@ -1,2 +1,3 @@
1
1
  # encoding: utf-8
2
+ require 'open_classes/fixnum/to_fixnum_html_table'
2
3
  require 'open_classes/fixnum/to_fixnum_table'
@@ -0,0 +1,98 @@
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 30 by 10 case
11
+ #
12
+ # Fixnum.to_fixnum_table(1, 30, 10)
13
+ #
14
+ # result
15
+ #
16
+ # <table>
17
+ # <tr>
18
+ # <td>1</td>
19
+ # <td>2</td>
20
+ # <td>3</td>
21
+ # <td>4</td>
22
+ # <td>5</td>
23
+ # <td>6</td>
24
+ # <td>7</td>
25
+ # <td>8</td>
26
+ # <td>9</td>
27
+ # <td>10</td>
28
+ # </tr>
29
+ # <tr>
30
+ # <td>11</td>
31
+ # <td>12</td>
32
+ # <td>13</td>
33
+ # <td>14</td>
34
+ # <td>15</td>
35
+ # <td>16</td>
36
+ # <td>17</td>
37
+ # <td>18</td>
38
+ # <td>19</td>
39
+ # <td>20</td>
40
+ # </tr>
41
+ # <tr>
42
+ # <td>21</td>
43
+ # <td>22</td>
44
+ # <td>23</td>
45
+ # <td>24</td>
46
+ # <td>25</td>
47
+ # <td>26</td>
48
+ # <td>27</td>
49
+ # <td>28</td>
50
+ # <td>29</td>
51
+ # <td>30</td>
52
+ # </tr>
53
+ # </table>
54
+ #
55
+ # 1 to 10 by 2 case
56
+ #
57
+ # Fixnum.to_fixnum_table(1, 10, 2)
58
+ #
59
+ # result
60
+ #
61
+ # <table>
62
+ # <tr>
63
+ # <td>1</td>
64
+ # <td>2</td>
65
+ # </tr>
66
+ # <tr>
67
+ # <td>3</td>
68
+ # <td>4</td>
69
+ # </tr>
70
+ # <tr>
71
+ # <td>5</td>
72
+ # <td>6</td>
73
+ # </tr>
74
+ # <tr>
75
+ # <td>7</td>
76
+ # <td>8</td>
77
+ # </tr>
78
+ # <tr>
79
+ # <td>9</td>
80
+ # <td>10</td>
81
+ # </tr>
82
+ # </table>
83
+ #
84
+ def self.to_fixnum_html_table(from = 1, to = 100, return_num = 10)
85
+ return '' unless from.is_a?(Fixnum)
86
+ return '' unless to.is_a?(Fixnum)
87
+ table_contents = [*from..to].each_slice(return_num).to_a.reduce([]) do |rets, row|
88
+ rets << ' <tr>'
89
+ rets << row.reduce([]) do |ret, column|
90
+ ret << " <td>#{column}</td>"
91
+ ret
92
+ end.join("\n")
93
+ rets << ' </tr>'
94
+ rets
95
+ end.join("\n")
96
+ "<table>\n" + table_contents + "\n</table>\n"
97
+ end
98
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.91'
5
+ VERSION = '0.0.92'
6
6
  end
@@ -11,7 +11,7 @@ describe Familyable::Family do
11
11
  persons: [
12
12
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
13
13
  b = Familyable::Person.new(id: 2, parent_ids: []),
14
- c = Familyable::Person.new(id: 3, parent_ids: [4], ),
14
+ c = Familyable::Person.new(id: 3, parent_ids: [4],),
15
15
  d = Familyable::Person.new(id: 4, parent_ids: []),
16
16
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
17
17
  ],
@@ -59,7 +59,7 @@ describe Familyable::Family do
59
59
  persons: [
60
60
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
61
61
  b = Familyable::Person.new(id: 2, parent_ids: []),
62
- c = Familyable::Person.new(id: 3, parent_ids: [4], ),
62
+ c = Familyable::Person.new(id: 3, parent_ids: [4],),
63
63
  d = Familyable::Person.new(id: 4, parent_ids: []),
64
64
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
65
65
  ],
@@ -107,7 +107,7 @@ describe Familyable::Family do
107
107
  persons: [
108
108
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
109
109
  b = Familyable::Person.new(id: 2, parent_ids: []),
110
- c = Familyable::Person.new(id: 3, parent_ids: [4], ),
110
+ c = Familyable::Person.new(id: 3, parent_ids: [4],),
111
111
  d = Familyable::Person.new(id: 4, parent_ids: [3]),
112
112
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
113
113
  ],
@@ -0,0 +1,215 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'open_classes/fixnum/to_fixnum_html_table'
4
+
5
+ describe Fixnum do
6
+ context :to_fixnum_html_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
+ <table>
16
+ <tr>
17
+ <td>1</td>
18
+ <td>2</td>
19
+ <td>3</td>
20
+ <td>4</td>
21
+ <td>5</td>
22
+ <td>6</td>
23
+ <td>7</td>
24
+ <td>8</td>
25
+ <td>9</td>
26
+ <td>10</td>
27
+ </tr>
28
+ <tr>
29
+ <td>11</td>
30
+ <td>12</td>
31
+ <td>13</td>
32
+ <td>14</td>
33
+ <td>15</td>
34
+ <td>16</td>
35
+ <td>17</td>
36
+ <td>18</td>
37
+ <td>19</td>
38
+ <td>20</td>
39
+ </tr>
40
+ <tr>
41
+ <td>21</td>
42
+ <td>22</td>
43
+ <td>23</td>
44
+ <td>24</td>
45
+ <td>25</td>
46
+ <td>26</td>
47
+ <td>27</td>
48
+ <td>28</td>
49
+ <td>29</td>
50
+ <td>30</td>
51
+ </tr>
52
+ <tr>
53
+ <td>31</td>
54
+ <td>32</td>
55
+ <td>33</td>
56
+ <td>34</td>
57
+ <td>35</td>
58
+ <td>36</td>
59
+ <td>37</td>
60
+ <td>38</td>
61
+ <td>39</td>
62
+ <td>40</td>
63
+ </tr>
64
+ <tr>
65
+ <td>41</td>
66
+ <td>42</td>
67
+ <td>43</td>
68
+ <td>44</td>
69
+ <td>45</td>
70
+ <td>46</td>
71
+ <td>47</td>
72
+ <td>48</td>
73
+ <td>49</td>
74
+ <td>50</td>
75
+ </tr>
76
+ <tr>
77
+ <td>51</td>
78
+ <td>52</td>
79
+ <td>53</td>
80
+ <td>54</td>
81
+ <td>55</td>
82
+ <td>56</td>
83
+ <td>57</td>
84
+ <td>58</td>
85
+ <td>59</td>
86
+ <td>60</td>
87
+ </tr>
88
+ <tr>
89
+ <td>61</td>
90
+ <td>62</td>
91
+ <td>63</td>
92
+ <td>64</td>
93
+ <td>65</td>
94
+ <td>66</td>
95
+ <td>67</td>
96
+ <td>68</td>
97
+ <td>69</td>
98
+ <td>70</td>
99
+ </tr>
100
+ <tr>
101
+ <td>71</td>
102
+ <td>72</td>
103
+ <td>73</td>
104
+ <td>74</td>
105
+ <td>75</td>
106
+ <td>76</td>
107
+ <td>77</td>
108
+ <td>78</td>
109
+ <td>79</td>
110
+ <td>80</td>
111
+ </tr>
112
+ <tr>
113
+ <td>81</td>
114
+ <td>82</td>
115
+ <td>83</td>
116
+ <td>84</td>
117
+ <td>85</td>
118
+ <td>86</td>
119
+ <td>87</td>
120
+ <td>88</td>
121
+ <td>89</td>
122
+ <td>90</td>
123
+ </tr>
124
+ <tr>
125
+ <td>91</td>
126
+ <td>92</td>
127
+ <td>93</td>
128
+ <td>94</td>
129
+ <td>95</td>
130
+ <td>96</td>
131
+ <td>97</td>
132
+ <td>98</td>
133
+ <td>99</td>
134
+ <td>100</td>
135
+ </tr>
136
+ </table>
137
+ EOS
138
+ },
139
+ {
140
+ case_no: 2,
141
+ case_title: '1-10, by2 case',
142
+ from: 1,
143
+ to: 10,
144
+ by: 2,
145
+ expected: <<-EOS
146
+ <table>
147
+ <tr>
148
+ <td>1</td>
149
+ <td>2</td>
150
+ </tr>
151
+ <tr>
152
+ <td>3</td>
153
+ <td>4</td>
154
+ </tr>
155
+ <tr>
156
+ <td>5</td>
157
+ <td>6</td>
158
+ </tr>
159
+ <tr>
160
+ <td>7</td>
161
+ <td>8</td>
162
+ </tr>
163
+ <tr>
164
+ <td>9</td>
165
+ <td>10</td>
166
+ </tr>
167
+ </table>
168
+ EOS
169
+ },
170
+ {
171
+ case_no: 3,
172
+ case_title: 'from is not Fixnum case',
173
+ from: '1',
174
+ to: 10,
175
+ by: 2,
176
+ expected: ''
177
+ },
178
+ {
179
+ case_no: 4,
180
+ case_title: 'to is not Fixnum case',
181
+ from: 1,
182
+ to: '10',
183
+ by: 2,
184
+ expected: ''
185
+ },
186
+ ]
187
+
188
+ cases.each do |c|
189
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
190
+ begin
191
+ case_before c
192
+
193
+ # -- given --
194
+ # nothing
195
+
196
+ # -- when --
197
+ actual = Fixnum.to_fixnum_html_table(c[:from], c[:to], c[:by])
198
+
199
+ # -- then --
200
+ expect(actual).to eq(c[:expected])
201
+ ensure
202
+ case_after c
203
+ end
204
+ end
205
+
206
+ def case_before(c)
207
+ # implement each case before
208
+ end
209
+
210
+ def case_after(c)
211
+ # implement each case after
212
+ end
213
+ end
214
+ end
215
+ 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.91
4
+ version: 0.0.92
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-04-08 00:00:00.000000000 Z
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &27952860 !ruby/object:Gem::Requirement
16
+ requirement: &21498684 !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: *27952860
24
+ version_requirements: *21498684
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &27952572 !ruby/object:Gem::Requirement
27
+ requirement: &21498396 !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: *27952572
35
+ version_requirements: *21498396
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &27952344 !ruby/object:Gem::Requirement
38
+ requirement: &21498168 !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: *27952344
46
+ version_requirements: *21498168
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &27952020 !ruby/object:Gem::Requirement
49
+ requirement: &21497844 !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: *27952020
57
+ version_requirements: *21497844
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &27951720 !ruby/object:Gem::Requirement
60
+ requirement: &21497544 !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: *27951720
68
+ version_requirements: *21497544
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -140,6 +140,7 @@ files:
140
140
  - lib/open_classes/array/together_with_index.rb
141
141
  - lib/open_classes/file.rb
142
142
  - lib/open_classes/fixnum.rb
143
+ - lib/open_classes/fixnum/to_fixnum_html_table.rb
143
144
  - lib/open_classes/fixnum/to_fixnum_table.rb
144
145
  - lib/open_classes/hash.rb
145
146
  - lib/open_classes/hash/table.rb
@@ -246,6 +247,7 @@ files:
246
247
  - spec/open_classes/array/together_spec.rb
247
248
  - spec/open_classes/array/together_with_index_spec.rb
248
249
  - spec/open_classes/file_spec.rb
250
+ - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
249
251
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
250
252
  - spec/open_classes/hash/table_spec.rb
251
253
  - spec/open_classes/kernel/aa_ancestors_spec.rb
@@ -372,6 +374,7 @@ test_files:
372
374
  - spec/open_classes/array/together_spec.rb
373
375
  - spec/open_classes/array/together_with_index_spec.rb
374
376
  - spec/open_classes/file_spec.rb
377
+ - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
375
378
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
376
379
  - spec/open_classes/hash/table_spec.rb
377
380
  - spec/open_classes/kernel/aa_ancestors_spec.rb