himekaminize 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc49f509e0f670ac3fcb69bcdc3afabfc3fdfe7f
4
- data.tar.gz: 77a2d8f192a27e43caa05499ab8e29011cb3a261
3
+ metadata.gz: 6861ce77d1b6849a5e62d90850f9c1112cb2ce78
4
+ data.tar.gz: d31f5223a6a3d4c9015bf062f47be8c78a682c80
5
5
  SHA512:
6
- metadata.gz: 952d607821e879de0d9ad6716ca886f3ea0c36dc677f1e3fc2a403b8fb73054ecd6a9ad31ff305f36d80c15d90bf6dbffe9d8bbb6a05bce4d876b04660cd9193
7
- data.tar.gz: 41d08096c5613851bc1494331454383faf4f717455b16663131dd3b50b055722fa048359b46d258ddde5c1ee2baf83f4c5b63dcebace8640a9fda18aaaf2bba6
6
+ metadata.gz: 78b7c30f47eb493215b54cf33951afa970d2041379e336354943729e1537766e81a05fbe8f09c78eff93e3cdc7cc1a467449683838433d88967fe81b8d13041a
7
+ data.tar.gz: adef4562190b45107faf0a12f171b3cd6ac09666d4df1e99499342ad8f8a812904ee91b399bd10e55693e13af74850da20ba409f26df3de9cbf05401a20ad2e8
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 otukutun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Himekaminize [![Build Status](https://travis-ci.org/otukutun/himekaminize.svg?branch=master)](https://travis-ci.org/otukutun/himekaminize)
1
+ # Himekaminize [![Build Status](https://travis-ci.org/otukutun/himekaminize.svg?branch=master)](https://travis-ci.org/otukutun/himekaminize) [![Gem Version](https://badge.fury.io/rb/himekaminize.svg)](https://badge.fury.io/rb/himekaminize)
2
2
 
3
3
  Utilities to extract markdown some parts.
4
4
 
@@ -0,0 +1,42 @@
1
+ require "active_support/concern"
2
+
3
+ module Himekaminize
4
+ module Filterable
5
+ extend ::ActiveSupport::Concern
6
+
7
+ def initialize(markdown)
8
+ @markdown = markdown
9
+ to_lines
10
+ end
11
+
12
+ def to_a
13
+ filters.inject(lines) do |result, filter|
14
+ filter.call(result)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def filters
21
+ @filters ||= self.class.filter_classes.map(&:new)
22
+ end
23
+
24
+ def markdown
25
+ @markdown
26
+ end
27
+
28
+ def lines
29
+ @lines
30
+ end
31
+
32
+ def to_lines
33
+ @lines = markdown.lines
34
+ end
35
+
36
+ module ClassMethods
37
+ def filter_classes
38
+ raise ::NotImplementedError
39
+ end
40
+ end
41
+ end
42
+ end
@@ -5,11 +5,16 @@ module Himekaminize
5
5
  # @param array [Array]
6
6
  # @return [Array]
7
7
  def call(array)
8
- array
9
- .select { |line| line.is_a?(String) && line =~ /\A\s*(#{Himekaminize::Task::INCOMPLETE_PATTERN}|#{Himekaminize::Task::COMPLETE_PATTERN})/ }
10
- .map.with_index {|n, idx| Himekaminize::Task.new(n, idx + 1)}
8
+ seq = 0
9
+ array.map do |line|
10
+ if line.is_a?(String) && line =~ /\A\s*(#{Himekaminize::Task::INCOMPLETE_PATTERN}|#{Himekaminize::Task::COMPLETE_PATTERN})/
11
+ seq += 1
12
+ Himekaminize::Task.new(line, seq)
13
+ else
14
+ line
15
+ end
16
+ end
11
17
  end
12
-
13
18
  end
14
19
  end
15
20
  end
@@ -1,32 +1,31 @@
1
1
  module Himekaminize
2
2
  class TaskList
3
+ include ::Himekaminize::Filterable
3
4
  class << self
4
5
  # @return [Array<Himekaminize::Filters::BaseFilter>]
5
- def filters
6
- @filters ||= [
7
- ::Himekaminize::Filters::TaskFilter.new
6
+ def filter_classes
7
+ @filter_classes ||= [
8
+ ::Himekaminize::Filters::TaskFilter
8
9
  ]
9
10
  end
10
11
  end
11
12
 
12
- # @param markdown [String]
13
- def initialize(markdown)
14
- @markdown = markdown
15
- to_lines
13
+ def to_task_list
14
+ array = to_a
15
+ array.select { |line| line.is_a?(Himekaminize::Task) }
16
16
  end
17
17
 
18
- # @todo
19
- # @param markdown [Array]
20
- def to_a
21
- self.class.filters.inject(@lines) do |result, filter|
22
- filter.call(result)
18
+ def to_s
19
+ array = to_a
20
+ seq = 0
21
+ array.map do |line|
22
+ if line.is_a?(Himekaminize::Task)
23
+ Himekaminize::Task.new(line, seq)
24
+ else
25
+ line
26
+ end
23
27
  end
24
- end
25
-
26
- private
27
-
28
- def to_lines
29
- @lines = @markdown.lines
28
+ .join("\n\r")
30
29
  end
31
30
  end
32
31
  end
@@ -1,3 +1,3 @@
1
1
  module Himekaminize
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/himekaminize.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "himekaminize/filterable"
1
2
  require "himekaminize/task"
2
3
  require "himekaminize/filters/base_filter"
3
4
  require "himekaminize/filters/task_filter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: himekaminize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - otukutun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-24 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -91,12 +91,14 @@ files:
91
91
  - ".rspec"
92
92
  - ".travis.yml"
93
93
  - Gemfile
94
+ - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
96
97
  - bin/console
97
98
  - bin/setup
98
99
  - himekaminize.gemspec
99
100
  - lib/himekaminize.rb
101
+ - lib/himekaminize/filterable.rb
100
102
  - lib/himekaminize/filters/base_filter.rb
101
103
  - lib/himekaminize/filters/task_filter.rb
102
104
  - lib/himekaminize/task.rb