tbpgr_utils 0.0.107 → 0.0.108

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -99,7 +99,8 @@ Or install it yourself as:
99
99
  |[MarkdownString.heading4](#markdownstringheading4) |Return markdown heading level4 from text |
100
100
  |[MarkdownString.heading5](#markdownstringheading5) |Return markdown heading level5 from text |
101
101
  |[MarkdownString.heading6](#markdownstringheading6) |Return markdown heading level6 from text |
102
- |[MarkdownString.ul](#markdownstringul) |Return markdown ul from arrau |
102
+ |[MarkdownString.ol](#markdownstringol) |Return markdown ol from array |
103
+ |[MarkdownString.ul](#markdownstringul) |Return markdown ul from array |
103
104
  |[MetasyntacticVariable](#metasyntacticvariable) |META variable, META variable for classes |
104
105
  |[TbpgrUtils Module.alias_methods](#modulealias_methods) |create alias methods |
105
106
  |[TbpgrUtils Numeric#dice_back](#numericdice_back) |return dice back number |
@@ -2352,6 +2353,45 @@ MarkdownString.heading6(12345) # => "###### 12345"
2352
2353
 
2353
2354
  [back to list](#list)
2354
2355
 
2356
+ ### MarkdownString.ol
2357
+ case list
2358
+ ~~~ruby
2359
+ require 'markdown_string'
2360
+ MarkdownString.ol(%w{a b c})
2361
+ ~~~
2362
+
2363
+ result
2364
+ ~~~
2365
+ 1. a
2366
+ 1. b
2367
+ 1. c
2368
+ ~~~
2369
+
2370
+ case not list
2371
+ ~~~ruby
2372
+ require 'markdown_string'
2373
+ MarkdownString.ol("test") # => "test"
2374
+
2375
+ case nil list
2376
+ ~~~ruby
2377
+ require 'markdown_string'
2378
+ MarkdownString.ol([nil, nil])
2379
+ ~~~
2380
+
2381
+ result
2382
+ ~~~
2383
+ 1.
2384
+ 1.
2385
+ ~~~
2386
+
2387
+ case empty list
2388
+ ~~~ruby
2389
+ require 'markdown_string'
2390
+ MarkdownString.ol([]) # => ""
2391
+ ~~~
2392
+
2393
+ [back to list](#list)
2394
+
2355
2395
  ### MarkdownString.ul
2356
2396
  case list
2357
2397
  ~~~ruby
@@ -2374,7 +2414,7 @@ MarkdownString.ul("test") # => "test"
2374
2414
  case nil list
2375
2415
  ~~~ruby
2376
2416
  require 'markdown_string'
2377
- MarkdownString.ul([nil, nil])
2417
+ MarkdownString.ul([nil, nil])
2378
2418
  ~~~
2379
2419
 
2380
2420
  result
@@ -3385,6 +3425,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3385
3425
  https://github.com/tbpgr/tbpgr_utils_snippets
3386
3426
 
3387
3427
  ## History
3428
+ * version 0.0.108 : add MarkdownString#ol
3388
3429
  * version 0.0.107 : add MarkdownString#ul
3389
3430
  * version 0.0.106 : add MarkdownString#heading3, heading4, heading5, heading6
3390
3431
  * version 0.0.105 : add MarkdownString#heading2
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ class MarkdownString
4
+ # Return markdown heading level1-6 from text
5
+ #
6
+ # === Example
7
+ #
8
+ # case list
9
+ #
10
+ # MarkdownString.ol(%w{a b c})
11
+ #
12
+ # resolt
13
+ #
14
+ # 1. a
15
+ # 1. b
16
+ # 1. c
17
+ #
18
+ # case not list
19
+ #
20
+ # MarkdownString.ol("test") # => "test"
21
+ #
22
+ # case nil list
23
+ #
24
+ # MarkdownString.ol([nil, nil])
25
+ #
26
+ # resolt
27
+ #
28
+ # 1.
29
+ # 1.
30
+ #
31
+ # case empty list
32
+ #
33
+ # MarkdownString.ol([]) # => ""
34
+ #
35
+ def self.ol(list)
36
+ return list unless list.is_a?(Array)
37
+ return '' if list.empty?
38
+ list.reduce([]) do |ret, elm|
39
+ elm = '' if elm.nil?
40
+ ret << "1. #{elm}"
41
+ ret
42
+ end.join("\n") + "\n"
43
+ end
44
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'markdown/heading'
4
+ require 'markdown/ol'
4
5
  require 'markdown/ul'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.107'
5
+ VERSION = '0.0.108'
6
6
  end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'markdown/ol'
4
+
5
+ describe MarkdownString do
6
+ context :ol do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'array case',
11
+ input: %w{a b c},
12
+ expected: <<-EOS
13
+ 1. a
14
+ 1. b
15
+ 1. c
16
+ EOS
17
+ },
18
+ {
19
+ case_no: 2,
20
+ case_title: 'not list case',
21
+ input: 'hoge',
22
+ expected: 'hoge',
23
+ },
24
+ {
25
+ case_no: 3,
26
+ case_title: 'empty list case',
27
+ input: [],
28
+ expected: '',
29
+ },
30
+ {
31
+ case_no: 4,
32
+ case_title: 'each element nil case',
33
+ input: [nil, nil, nil],
34
+ expected: <<-EOS
35
+ 1.
36
+ 1.
37
+ 1.
38
+ EOS
39
+ },
40
+ ]
41
+
42
+ cases.each do |c|
43
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
44
+ begin
45
+ case_before c
46
+
47
+ # -- given --
48
+ # nothing
49
+
50
+ # -- when --
51
+ actual = MarkdownString.ol c[:input]
52
+
53
+ # -- then --
54
+ expect(actual).to eq(c[:expected])
55
+ ensure
56
+ case_after c
57
+ end
58
+ end
59
+
60
+ def case_before(c)
61
+ # implement each case before
62
+ end
63
+
64
+ def case_after(c)
65
+ # implement each case after
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'markdown/ul'
4
+
5
+ describe MarkdownString do
6
+ context :ul do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'array case',
11
+ input: %w{a b c},
12
+ expected: <<-EOS
13
+ * a
14
+ * b
15
+ * c
16
+ EOS
17
+ },
18
+ {
19
+ case_no: 2,
20
+ case_title: 'not list case',
21
+ input: 'hoge',
22
+ expected: 'hoge',
23
+ },
24
+ {
25
+ case_no: 3,
26
+ case_title: 'empty list case',
27
+ input: [],
28
+ expected: '',
29
+ },
30
+ {
31
+ case_no: 4,
32
+ case_title: 'each element nil case',
33
+ input: [nil, nil, nil],
34
+ expected: <<-EOS
35
+ *
36
+ *
37
+ *
38
+ EOS
39
+ },
40
+ ]
41
+
42
+ cases.each do |c|
43
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
44
+ begin
45
+ case_before c
46
+
47
+ # -- given --
48
+ # nothing
49
+
50
+ # -- when --
51
+ actual = MarkdownString.ul c[:input]
52
+
53
+ # -- then --
54
+ expect(actual).to eq(c[:expected])
55
+ ensure
56
+ case_after c
57
+ end
58
+ end
59
+
60
+ def case_before(c)
61
+ # implement each case before
62
+ end
63
+
64
+ def case_after(c)
65
+ # implement each case after
66
+ end
67
+ end
68
+ end
69
+ 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.107
4
+ version: 0.0.108
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-24 00:00:00.000000000 Z
12
+ date: 2014-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &21118152 !ruby/object:Gem::Requirement
16
+ requirement: &24532488 !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: *21118152
24
+ version_requirements: *24532488
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &21117864 !ruby/object:Gem::Requirement
27
+ requirement: &24532200 !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: *21117864
35
+ version_requirements: *24532200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &21117636 !ruby/object:Gem::Requirement
38
+ requirement: &24531972 !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: *21117636
46
+ version_requirements: *24531972
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &21117312 !ruby/object:Gem::Requirement
49
+ requirement: &24531648 !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: *21117312
57
+ version_requirements: *24531648
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &21117012 !ruby/object:Gem::Requirement
60
+ requirement: &24531348 !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: *21117012
68
+ version_requirements: *24531348
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -109,6 +109,7 @@ files:
109
109
  - lib/familyable/person.rb
110
110
  - lib/ghostable.rb
111
111
  - lib/markdown/heading.rb
112
+ - lib/markdown/ol.rb
112
113
  - lib/markdown/ul.rb
113
114
  - lib/markdown_string.rb
114
115
  - lib/metasyntactic_variable.rb
@@ -233,6 +234,8 @@ files:
233
234
  - spec/familyable/familyable_spec.rb
234
235
  - spec/ghostable_spec.rb
235
236
  - spec/markdown/heading_spec.rb
237
+ - spec/markdown/ol_spec.rb
238
+ - spec/markdown/ul_spec.rb
236
239
  - spec/metasyntactic_variable_spec.rb
237
240
  - spec/open_classes/array/to_html_table_spec.rb
238
241
  - spec/open_classes/array/to_table_spec.rb
@@ -371,6 +374,8 @@ test_files:
371
374
  - spec/familyable/familyable_spec.rb
372
375
  - spec/ghostable_spec.rb
373
376
  - spec/markdown/heading_spec.rb
377
+ - spec/markdown/ol_spec.rb
378
+ - spec/markdown/ul_spec.rb
374
379
  - spec/metasyntactic_variable_spec.rb
375
380
  - spec/open_classes/array/to_html_table_spec.rb
376
381
  - spec/open_classes/array/to_table_spec.rb