tbpgr_utils 0.0.103 → 0.0.104

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -76,7 +76,6 @@ Or install it yourself as:
76
76
  |[EvalHelper#unless_code](#evalhelperunless_code) |create unless strings, for eval |
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
- |[TbpgrUtils File.insert_bom](#fileinsert_bom) |insert BOM to UTF-8 File |
80
79
  |[TbpgrUtils Fixnum to_fixnum_html_table](#fixnum-to_fixnum_html_table) |return value is fixnum html table |
81
80
  |[TbpgrUtils Fixnum to_fixnum_table](#fixnumto_fixnum_table) |return value is fixnum table |
82
81
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
@@ -94,6 +93,7 @@ Or install it yourself as:
94
93
  |[TbpgrUtils Kernel#null](#kernelnull) |null is alias of nil |
95
94
  |[TbpgrUtils Kernel#print_eval](#kernelprint_eval) |Print code + eval result |
96
95
  |[TbpgrUtils Kernel#puts_eval](#kernelputs_eval) |Puts code + eval result |
96
+ |[MarkdownString.heading1](#markdownstringheading1) |Return markdown heading level1 from text |
97
97
  |[MetasyntacticVariable](#metasyntacticvariable) |META variable, META variable for classes |
98
98
  |[TbpgrUtils Module.alias_methods](#modulealias_methods) |create alias methods |
99
99
  |[TbpgrUtils Numeric#dice_back](#numericdice_back) |return dice back number |
@@ -1249,25 +1249,6 @@ Create model that has two fileds that are 'id' and 'parent_ids'.
1249
1249
 
1250
1250
  [back to list](#list)
1251
1251
 
1252
- ### File.insert_bom
1253
- * this method's main purpose is 'UTF-8 Excel CSV File'.
1254
-
1255
- output bommed text from input.csv to output.csv
1256
- ~~~ruby
1257
- require 'tbpgr_utils'
1258
-
1259
- File.insert_bom("input.csv", "output.csv") # => output bommed text to output.csv
1260
- ~~~
1261
-
1262
- output bommed text from input.csv to input.csv
1263
- ~~~ruby
1264
- require 'tbpgr_utils'
1265
-
1266
- File.insert_bom("input.csv") # => output bommed text to output.csv
1267
- ~~~
1268
-
1269
- [back to list](#list)
1270
-
1271
1252
  ### Fixnum.to_fixnum_html_table
1272
1253
  1 to 10 by 2 case
1273
1254
  ~~~ruby
@@ -2302,6 +2283,17 @@ EvalHelperTest.new.hoge(hash) # => return 'default'
2302
2283
 
2303
2284
  [back to list](#list)
2304
2285
 
2286
+ ### MarkdownString.heading1
2287
+ ~~~ruby
2288
+ require 'markdown_string'
2289
+ MarkdownString.heading1("title") # => "# title"
2290
+ MarkdownString.heading1("") # => "# "
2291
+ MarkdownString.heading1(nil) # => "# "
2292
+ MarkdownString.heading1(12345) # => "# 12345"
2293
+ ~~~
2294
+
2295
+ [back to list](#list)
2296
+
2305
2297
  ### MetasyntacticVariable
2306
2298
  * META variable
2307
2299
 
@@ -3296,6 +3288,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3296
3288
  https://github.com/tbpgr/tbpgr_utils_snippets
3297
3289
 
3298
3290
  ## History
3291
+ * version 0.0.104 : add MarkdownString#heading1. remove File.insert_bom.
3299
3292
  * version 0.0.103 : add Integer#palindromic_prime
3300
3293
  * version 0.0.102 : add String#cygwinpath_to_winpath
3301
3294
  * version 0.0.101 : add String#winpath_to_cygwinpath
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ class MarkdownString
4
+ # Return markdown heading level1 from text
5
+ #
6
+ # === Example
7
+ #
8
+ # MarkdownString.heading1("title") # => "# title"
9
+ # MarkdownString.heading1("") # => "# "
10
+ # MarkdownString.heading1(nil) # => "# "
11
+ # MarkdownString.heading1(12345) # => "# 12345"
12
+ #
13
+ def self.heading1(text)
14
+ return '# ' if text.nil?
15
+ return '# ' if text.respond_to?(:empty) && text.empty?
16
+ "# #{text.to_s}"
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require 'markdown/heading'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.103'
5
+ VERSION = '0.0.104'
6
6
  end
data/lib/tbpgr_utils.rb CHANGED
@@ -4,7 +4,6 @@ require 'tbpgr_utils/version'
4
4
  # Tbpgr Utilities
5
5
  module TbpgrUtils
6
6
  require 'open_classes/array'
7
- require 'open_classes/file'
8
7
  require 'open_classes/fixnum'
9
8
  require 'open_classes/hash'
10
9
  require 'open_classes/integer'
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'markdown/heading'
4
+
5
+ describe MarkdownString do
6
+ context :header1 do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'normal case',
11
+ input: 'header1',
12
+ expected: '# header1',
13
+ },
14
+ {
15
+ case_no: 2,
16
+ case_title: 'empty case',
17
+ input: '',
18
+ expected: '# ',
19
+ },
20
+ {
21
+ case_no: 3,
22
+ case_title: 'nil case',
23
+ input: '',
24
+ expected: '# ',
25
+ },
26
+ {
27
+ case_no: 3,
28
+ case_title: 'not String case',
29
+ input: 12_345,
30
+ expected: '# 12345',
31
+ },
32
+ ]
33
+
34
+ cases.each do |c|
35
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
36
+ begin
37
+ case_before c
38
+
39
+ # -- given --
40
+ # nothing
41
+
42
+ # -- when --
43
+ actual = MarkdownString.heading1 c[:input]
44
+
45
+ # -- then --
46
+ expect(actual).to eq(c[:expected])
47
+ ensure
48
+ case_after c
49
+ end
50
+ end
51
+
52
+ def case_before(c)
53
+ # implement each case before
54
+ end
55
+
56
+ def case_after(c)
57
+ # implement each case after
58
+ end
59
+ end
60
+ end
61
+ 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.103
4
+ version: 0.0.104
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-20 00:00:00.000000000 Z
12
+ date: 2014-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &26225532 !ruby/object:Gem::Requirement
16
+ requirement: &21962160 !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: *26225532
24
+ version_requirements: *21962160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &26224980 !ruby/object:Gem::Requirement
27
+ requirement: &21961872 !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: *26224980
35
+ version_requirements: *21961872
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &26224572 !ruby/object:Gem::Requirement
38
+ requirement: &21961644 !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: *26224572
46
+ version_requirements: *21961644
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &26223756 !ruby/object:Gem::Requirement
49
+ requirement: &21961320 !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: *26223756
57
+ version_requirements: *21961320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &26223312 !ruby/object:Gem::Requirement
60
+ requirement: &21961020 !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: *26223312
68
+ version_requirements: *21961020
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -108,6 +108,8 @@ files:
108
108
  - lib/familyable/familynize.rb
109
109
  - lib/familyable/person.rb
110
110
  - lib/ghostable.rb
111
+ - lib/markdown/heading.rb
112
+ - lib/markdown_string.rb
111
113
  - lib/metasyntactic_variable.rb
112
114
  - lib/open_classes/array.rb
113
115
  - lib/open_classes/array/to_html_table.rb
@@ -138,7 +140,6 @@ files:
138
140
  - lib/open_classes/array/together_shuffle.rb
139
141
  - lib/open_classes/array/together_slice.rb
140
142
  - lib/open_classes/array/together_with_index.rb
141
- - lib/open_classes/file.rb
142
143
  - lib/open_classes/fixnum.rb
143
144
  - lib/open_classes/fixnum/to_fixnum_html_table.rb
144
145
  - lib/open_classes/fixnum/to_fixnum_table.rb
@@ -230,6 +231,7 @@ files:
230
231
  - spec/eval_helper/unless_code_spec.rb
231
232
  - spec/familyable/familyable_spec.rb
232
233
  - spec/ghostable_spec.rb
234
+ - spec/markdown/heading_spec.rb
233
235
  - spec/metasyntactic_variable_spec.rb
234
236
  - spec/open_classes/array/to_html_table_spec.rb
235
237
  - spec/open_classes/array/to_table_spec.rb
@@ -258,7 +260,6 @@ files:
258
260
  - spec/open_classes/array/together_slice_spec.rb
259
261
  - spec/open_classes/array/together_spec.rb
260
262
  - spec/open_classes/array/together_with_index_spec.rb
261
- - spec/open_classes/file_spec.rb
262
263
  - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
263
264
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
264
265
  - spec/open_classes/hash/html_table_spec.rb
@@ -368,6 +369,7 @@ test_files:
368
369
  - spec/eval_helper/unless_code_spec.rb
369
370
  - spec/familyable/familyable_spec.rb
370
371
  - spec/ghostable_spec.rb
372
+ - spec/markdown/heading_spec.rb
371
373
  - spec/metasyntactic_variable_spec.rb
372
374
  - spec/open_classes/array/to_html_table_spec.rb
373
375
  - spec/open_classes/array/to_table_spec.rb
@@ -396,7 +398,6 @@ test_files:
396
398
  - spec/open_classes/array/together_slice_spec.rb
397
399
  - spec/open_classes/array/together_spec.rb
398
400
  - spec/open_classes/array/together_with_index_spec.rb
399
- - spec/open_classes/file_spec.rb
400
401
  - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
401
402
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
402
403
  - spec/open_classes/hash/html_table_spec.rb
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # File
4
- class File
5
- # insert BOM to UTF-8 File
6
- #
7
- # this method's main purpose is 'UTF-8 Excel CSV File'.
8
- #
9
- # File.insert_bom("input.csv", "output.csv") # => output bommed text to output.csv
10
- # File.insert_bom("input.csv") # => output bommed text to input.csv
11
- def self.insert_bom(input_filename, output_filename = nil)
12
- src = File.read(input_filename)
13
- output_filename ||= input_filename
14
- File.open(output_filename, 'w:UTF-8') do |f|
15
- src = ' ' + src
16
- src.setbyte(0, 0xEF)
17
- src.setbyte(1, 0xBB)
18
- src.setbyte(2, 0xBF)
19
- f.print src
20
- end
21
- end
22
- end
@@ -1,76 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'tbpgr_utils'
4
-
5
- describe File do
6
- context :insert_bom do
7
- INSERT_BOM_TMP = 'insert_bom_tmp'
8
- FILE_CONTENTS = <<-EOS
9
- タイトル1,タイトル2,タイトル3
10
- 行1_1,行1_2,行1_3
11
- 行2_1,行2_2,行2_3
12
- EOS
13
-
14
- cases = [
15
- {
16
- case_no: 1,
17
- case_title: 'valid case',
18
- input: 'input',
19
- output: 'output',
20
- src: FILE_CONTENTS,
21
- expected: [0xEF, 0xBB, 0xBF],
22
- },
23
- {
24
- case_no: 2,
25
- case_title: 'if no output-file, then write to input-file case',
26
- input: 'input',
27
- output: nil,
28
- src: FILE_CONTENTS,
29
- expected: [0xEF, 0xBB, 0xBF],
30
- },
31
- ]
32
-
33
- cases.each do |c|
34
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
35
- begin
36
- case_before c
37
-
38
- # -- given --
39
- # nothing
40
-
41
- # -- when --
42
- File.insert_bom c[:input], c[:output]
43
-
44
- # -- then --
45
- c[:output] = c[:input] if c[:output].nil?
46
- actual = File.read(c[:output])
47
- base_bytes = []
48
- actual.bytes.each_with_index do |v, index|
49
- if index < 3
50
- expect(v).to eq(c[:expected][index])
51
- else
52
- base_bytes << v
53
- end
54
- end
55
- expect(base_bytes).to eq(c[:src].bytes.to_a)
56
- ensure
57
- case_after c
58
- end
59
- end
60
-
61
- def case_before(c)
62
- # implement each case before
63
- Dir.mkdir(INSERT_BOM_TMP) unless File.exists?(INSERT_BOM_TMP)
64
- Dir.chdir(INSERT_BOM_TMP)
65
- File.open(c[:input], 'w:UTF-8') { |f|f.print c[:src] }
66
- end
67
-
68
- def case_after(c)
69
- # implement each case after
70
- Dir.chdir('../')
71
- return unless File.exists? INSERT_BOM_TMP
72
- FileUtils.rm_rf("./#{INSERT_BOM_TMP}")
73
- end
74
- end
75
- end
76
- end