himekaminize 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ee0efeadb1fc9a2e487208e29e66a9b63a73dad
4
- data.tar.gz: 1f366c309ce50a78c7709526309dfd68d8db8390
3
+ metadata.gz: f444a2dd0b3b1a97f966b035e42e2ead3e020dfb
4
+ data.tar.gz: 71c106773ece5d68fe0aff957b2ed297c32ad7fb
5
5
  SHA512:
6
- metadata.gz: a53feb0f0527c8417442b3cfb1bc176c61849ccd5d9d7176a89a9c37bd5a236346b51b33aefe62595419cfeac0ab510532a3d887c802613a5c8682b78fde3e5a
7
- data.tar.gz: 0d62044335ce6d0f9dd6de9515f870973eb5b19d1e9873562c51723b0ed883975177c5e1aa35122a9ae0dbc1306aa2205be421286543322b6d6bdc2b764088ae
6
+ metadata.gz: f3c09adcbbb268dff3c9f06e5eaf7ac66e9c58ca1b7742de93c659843f1c765c286d68ea7d349c552f52411d57439d0c5baf3f5ff49793a4da652829d1c40ef8
7
+ data.tar.gz: a8ba725a9fe4066c4c7f15bcff00710d81d87ad0706ab19f0f97c9be7d126f462dfbce90fb3b23a543f0a2ac2aa1a93d671353efee3dcb1b8d1d11c179c370aa
@@ -1,20 +1,23 @@
1
1
  require "active_support/concern"
2
-
3
2
  module Himekaminize
4
3
  module Filterable
5
4
  extend ::ActiveSupport::Concern
6
5
 
7
- def initialize(markdown)
6
+ def initialize(default_context = {})
7
+ @default_context = default_context
8
+ end
9
+
10
+ def call(markdown, context = {})
8
11
  @markdown = markdown
9
12
  to_lines
10
13
  @result ||= Hash.new
11
- end
14
+ context = default_context.merge(context)
15
+
16
+ @result = filters.inject(context: context, output: lines) do |output, filter|
17
+ filter.call(output)
18
+ end
12
19
 
13
- def call
14
- result[:output] =
15
- filters.inject(lines) do |output, filter|
16
- filter.call(output)
17
- end
20
+ @result
18
21
  end
19
22
 
20
23
  def result
@@ -31,6 +34,14 @@ module Himekaminize
31
34
  @markdown
32
35
  end
33
36
 
37
+ def context
38
+ @context
39
+ end
40
+
41
+ def default_context
42
+ @default_context
43
+ end
44
+
34
45
  def lines
35
46
  @lines
36
47
  end
@@ -1,9 +1,10 @@
1
1
  module Himekaminize
2
2
  module Filters
3
3
  class BaseFilter
4
- # @param array [Array]
5
- # @return [Array]
6
- def call(array)
4
+ # @param context [Hash]
5
+ # @param output [String]
6
+ # @return [Hash]
7
+ def call(context:, output:)
7
8
  raise ::NotImplementedError
8
9
  end
9
10
  end
@@ -1,12 +1,11 @@
1
+ require "himekaminize/filters/base_filter"
1
2
  module Himekaminize
2
3
  module Filters
3
4
  class TaskFilter < BaseFilter
4
- # @note Override
5
- # @param array [Array]
6
- # @return [Array]
7
- def call(array)
5
+ def call(context:, output:)
8
6
  seq = 0
9
- array.map do |line|
7
+ @context = context
8
+ output = output.map do |line|
10
9
  if line.is_a?(String) && line =~ /\A\s*(#{Himekaminize::Task::INCOMPLETE_PATTERN}|#{Himekaminize::Task::COMPLETE_PATTERN})/
11
10
  seq += 1
12
11
  Himekaminize::Task.new(line, seq)
@@ -14,6 +13,40 @@ module Himekaminize
14
13
  line
15
14
  end
16
15
  end
16
+
17
+ if only_task_list?
18
+ output = output.select { |line| line.is_a?(Himekaminize::Task) }
19
+ end
20
+
21
+ if update_task_status_list.present?
22
+ seq = 1
23
+ update_task_status_list.each do |v|
24
+ output = output.map do |line|
25
+ if line.is_a?(Himekaminize::Task) && line.sequence == v[:sequence]
26
+ line.update_status(v[:status].to_sym)
27
+ line
28
+ else
29
+ line
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ {
37
+ context: context,
38
+ output: output,
39
+ }
40
+ end
41
+
42
+ private
43
+
44
+ def only_task_list?
45
+ @context[:only_task_list].presence || false
46
+ end
47
+
48
+ def update_task_status_list
49
+ @context[:update_task_status_list].presence || {}
17
50
  end
18
51
  end
19
52
  end
@@ -21,6 +21,11 @@ module Himekaminize
21
21
  sprintf("%s%s %s", @space, status_str, @name)
22
22
  end
23
23
 
24
+ def update_status(status)
25
+ return false unless STATUSES.include?(status)
26
+ @status = status
27
+ end
28
+
24
29
  private
25
30
  def split_name_and_status(line)
26
31
  /\A(\s)*(#{INCOMPLETE_PATTERN}|#{COMPLETE_PATTERN})(.*)/.match(line) do |m|
@@ -10,34 +10,5 @@ module Himekaminize
10
10
  ]
11
11
  end
12
12
  end
13
-
14
- def to_task_list
15
- array = result.try(:output) || call
16
- result[:task_list] = array.select { |line| line.is_a?(Himekaminize::Task) }
17
- end
18
-
19
- def update_task_status(sequence, status)
20
- return false unless ::Himekaminize::Task::STATUSES.include?(status)
21
- result[:task_list] = result.try(:task_list) || to_task_list
22
- if sequence.is_a?(Integer) && sequence > 0 && (1..result[:task_list].count).cover?(sequence)
23
- result[:task_list][sequence - 1].status = status
24
- else
25
- false
26
- end
27
- true
28
- end
29
-
30
- def to_s
31
- array = result.try(:output) || call
32
- seq = 0
33
- array.map do |line|
34
- if line.is_a?(::Himekaminize::Task)
35
- line.to_s + "\n\r"
36
- else
37
- line
38
- end
39
- end
40
- .join('')
41
- end
42
13
  end
43
14
  end
@@ -1,3 +1,3 @@
1
1
  module Himekaminize
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - otukutun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport