himekaminize 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/himekaminize/filters/header_filter.rb +43 -0
- data/lib/himekaminize/filters/task_filter.rb +4 -4
- data/lib/himekaminize/nodes/base_node.rb +9 -0
- data/lib/himekaminize/nodes/header.rb +30 -0
- data/lib/himekaminize/nodes/task.rb +42 -0
- data/lib/himekaminize/outline.rb +14 -0
- data/lib/himekaminize/version.rb +1 -1
- data/lib/himekaminize.rb +5 -1
- metadata +7 -3
- data/lib/himekaminize/task.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cde3b0ebaa66408891147dffeb1bc467e575416
|
4
|
+
data.tar.gz: 7abc0cb4194a9ec8922a24b01200d25c091a3c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 966d5bf23b2984ccd95bae0a907ae0320c6439c54ae01533577cb16ee974dbb7d72c38e23e63af70488ff63dec88afe4e804328cb31793f7416fd7992a3fb769
|
7
|
+
data.tar.gz: a7de0121fa2027368ce413ce35fe1f84176d5c0671f3496a5c948905d5cee287ab9d9a1a88feab5f1b49a70ca13d0bae748877e6c4e0ee49169addb3d16596b4
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "himekaminize/filters/base_filter"
|
2
|
+
module Himekaminize
|
3
|
+
module Filters
|
4
|
+
class HeaderFilter < BaseFilter
|
5
|
+
DEFAULT_HEADER_SIZE = 6
|
6
|
+
def call(context:, output:)
|
7
|
+
@context = context
|
8
|
+
output = output.map do |line|
|
9
|
+
if line.is_a?(String) && line =~ /\A\s*(#{Himekaminize::Nodes::Header::PATTERN})/
|
10
|
+
Himekaminize::Nodes::Header.new(line)
|
11
|
+
else
|
12
|
+
line
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if only_header?
|
17
|
+
output = output.select { |line| line.is_a?(Himekaminize::Nodes::Header) }
|
18
|
+
end
|
19
|
+
|
20
|
+
if header_size.present?
|
21
|
+
output = output.select { |line|
|
22
|
+
(line.is_a?(Himekaminize::Nodes::Header) && header_size >= line.size) || !line.is_a?(Himekaminize::Nodes::Header)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
{
|
27
|
+
context: context,
|
28
|
+
output: output,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def only_header?
|
35
|
+
@context[:only_header].presence || false
|
36
|
+
end
|
37
|
+
|
38
|
+
def header_size
|
39
|
+
@context[:header_size].presence || DEFAULT_HEADER_SIZE
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -6,23 +6,23 @@ module Himekaminize
|
|
6
6
|
seq = 0
|
7
7
|
@context = context
|
8
8
|
output = output.map do |line|
|
9
|
-
if line.is_a?(String) && line =~ /\A\s*(#{Himekaminize::Task::INCOMPLETE_PATTERN}|#{Himekaminize::Task::COMPLETE_PATTERN})/
|
9
|
+
if line.is_a?(String) && line =~ /\A\s*(#{Himekaminize::Nodes::Task::INCOMPLETE_PATTERN}|#{Himekaminize::Nodes::Task::COMPLETE_PATTERN})/
|
10
10
|
seq += 1
|
11
|
-
Himekaminize::Task.new(line, seq)
|
11
|
+
Himekaminize::Nodes::Task.new(line, seq)
|
12
12
|
else
|
13
13
|
line
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
if only_task_list?
|
18
|
-
output = output.select { |line| line.is_a?(Himekaminize::Task) }
|
18
|
+
output = output.select { |line| line.is_a?(Himekaminize::Nodes::Task) }
|
19
19
|
end
|
20
20
|
|
21
21
|
if update_task_status_list.present?
|
22
22
|
seq = 1
|
23
23
|
update_task_status_list.each do |v|
|
24
24
|
output = output.map do |line|
|
25
|
-
if line.is_a?(Himekaminize::Task) && line.sequence == v[:sequence]
|
25
|
+
if line.is_a?(Himekaminize::Nodes::Task) && line.sequence == v[:sequence]
|
26
26
|
line.update_status(v[:status].to_sym)
|
27
27
|
line
|
28
28
|
else
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Himekaminize
|
2
|
+
module Nodes
|
3
|
+
class Header < BaseNode
|
4
|
+
|
5
|
+
PATTERN = /\#{1,6}/
|
6
|
+
attr_accessor :space, :name, :level, :size
|
7
|
+
|
8
|
+
def initialize(line)
|
9
|
+
@space, @level, @name = split_name_and_level(line)
|
10
|
+
@size = count_size
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
sprintf("%s%s%s\n", @space, @level, @name)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def split_name_and_level(line)
|
20
|
+
/\A(\s*)(#{PATTERN})(.*)/.match(line) do |m|
|
21
|
+
[m[1], m[2], m[3]]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def count_size
|
26
|
+
@level.length
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Himekaminize
|
2
|
+
module Nodes
|
3
|
+
class Task < BaseNode
|
4
|
+
INCOMPLETE_PATTERN = /[-+*]\s\[\s\]\s/
|
5
|
+
COMPLETE_PATTERN = /[-+*]\s\[[xX]\]\s/
|
6
|
+
|
7
|
+
INCOMPLETE_MD = '- [ ]'.freeze
|
8
|
+
COMPLETE_MD = '- [x]'.freeze
|
9
|
+
attr_accessor :name, :status, :sequence
|
10
|
+
|
11
|
+
COMPLETE_STATUSE = :complete
|
12
|
+
INCOMPLETE_STATUSE = :incomplete
|
13
|
+
STATUSES = %I(#{COMPLETE_STATUSE} #{INCOMPLETE_STATUSE})
|
14
|
+
|
15
|
+
def initialize(line, sequence)
|
16
|
+
@sequence = sequence
|
17
|
+
@status, @name, @space = split_name_and_status(line)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
status_str = @status == COMPLETE_STATUSE ? COMPLETE_MD : INCOMPLETE_MD
|
22
|
+
sprintf("%s%s %s\n", @space, status_str, @name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_status(status)
|
26
|
+
return false unless STATUSES.include?(status)
|
27
|
+
@status = status
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def split_name_and_status(line)
|
32
|
+
/\A(\s*)(#{INCOMPLETE_PATTERN}|#{COMPLETE_PATTERN})(.*)/.match(line) do |m|
|
33
|
+
if m[2] =~ /#{INCOMPLETE_PATTERN}/
|
34
|
+
return [INCOMPLETE_STATUSE, m[3], m[1]]
|
35
|
+
else
|
36
|
+
return [COMPLETE_STATUSE, m[3], m[1]]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_support/core_ext/object"
|
2
|
+
module Himekaminize
|
3
|
+
class Outline
|
4
|
+
include ::Himekaminize::Filterable
|
5
|
+
class << self
|
6
|
+
# @return [Array<Himekaminize::Filters::BaseFilter>]
|
7
|
+
def filter_classes
|
8
|
+
@filter_classes ||= [
|
9
|
+
::Himekaminize::Filters::HeaderFilter
|
10
|
+
]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/himekaminize/version.rb
CHANGED
data/lib/himekaminize.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "himekaminize/filterable"
|
2
|
-
require "himekaminize/
|
2
|
+
require "himekaminize/nodes/base_node"
|
3
|
+
require "himekaminize/nodes/task"
|
4
|
+
require "himekaminize/nodes/header"
|
3
5
|
require "himekaminize/filters/base_filter"
|
4
6
|
require "himekaminize/filters/task_filter"
|
7
|
+
require "himekaminize/filters/header_filter"
|
8
|
+
require "himekaminize/outline"
|
5
9
|
require "himekaminize/task_list"
|
6
10
|
require "himekaminize/version"
|
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
|
+
version: 0.0.10
|
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-
|
11
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,8 +100,12 @@ files:
|
|
100
100
|
- lib/himekaminize.rb
|
101
101
|
- lib/himekaminize/filterable.rb
|
102
102
|
- lib/himekaminize/filters/base_filter.rb
|
103
|
+
- lib/himekaminize/filters/header_filter.rb
|
103
104
|
- lib/himekaminize/filters/task_filter.rb
|
104
|
-
- lib/himekaminize/
|
105
|
+
- lib/himekaminize/nodes/base_node.rb
|
106
|
+
- lib/himekaminize/nodes/header.rb
|
107
|
+
- lib/himekaminize/nodes/task.rb
|
108
|
+
- lib/himekaminize/outline.rb
|
105
109
|
- lib/himekaminize/task_list.rb
|
106
110
|
- lib/himekaminize/version.rb
|
107
111
|
homepage: https://github.com/otukutun/himekaminize
|
data/lib/himekaminize/task.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Himekaminize
|
2
|
-
class Task
|
3
|
-
INCOMPLETE_PATTERN = /[-+*]\s\[\s\]\s/
|
4
|
-
COMPLETE_PATTERN = /[-+*]\s\[[xX]\]\s/
|
5
|
-
|
6
|
-
INCOMPLETE_MD = '- [ ]'.freeze
|
7
|
-
COMPLETE_MD = '- [x]'.freeze
|
8
|
-
attr_accessor :name, :status, :sequence
|
9
|
-
|
10
|
-
COMPLETE_STATUSE = :complete
|
11
|
-
INCOMPLETE_STATUSE = :incomplete
|
12
|
-
STATUSES = %I(#{COMPLETE_STATUSE} #{INCOMPLETE_STATUSE})
|
13
|
-
|
14
|
-
def initialize(line, sequence)
|
15
|
-
@sequence = sequence
|
16
|
-
@status, @name, @space = split_name_and_status(line)
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
status_str = @status == COMPLETE_STATUSE ? COMPLETE_MD : INCOMPLETE_MD
|
21
|
-
sprintf("%s%s %s\n", @space, status_str, @name)
|
22
|
-
end
|
23
|
-
|
24
|
-
def update_status(status)
|
25
|
-
return false unless STATUSES.include?(status)
|
26
|
-
@status = status
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def split_name_and_status(line)
|
31
|
-
/\A(\s*)(#{INCOMPLETE_PATTERN}|#{COMPLETE_PATTERN})(.*)/.match(line) do |m|
|
32
|
-
if m[2] =~ /#{INCOMPLETE_PATTERN}/
|
33
|
-
return [INCOMPLETE_STATUSE, m[3], m[1]]
|
34
|
-
else
|
35
|
-
return [COMPLETE_STATUSE, m[3], m[1]]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|