himekaminize 0.0.2 → 0.0.3

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: 6861ce77d1b6849a5e62d90850f9c1112cb2ce78
4
- data.tar.gz: d31f5223a6a3d4c9015bf062f47be8c78a682c80
3
+ metadata.gz: 1b69acba8db048b9dd28e2cd314106e062a1c826
4
+ data.tar.gz: c454ccc246f88afc89fb05acde3b9c2b3b8b9ff4
5
5
  SHA512:
6
- metadata.gz: 78b7c30f47eb493215b54cf33951afa970d2041379e336354943729e1537766e81a05fbe8f09c78eff93e3cdc7cc1a467449683838433d88967fe81b8d13041a
7
- data.tar.gz: adef4562190b45107faf0a12f171b3cd6ac09666d4df1e99499342ad8f8a812904ee91b399bd10e55693e13af74850da20ba409f26df3de9cbf05401a20ad2e8
6
+ metadata.gz: 1ff4fb8942823ddce906a9f2d620e40b53cb6ac9e57ec6c33180abd1742b9d66623ec04387bdc9c91f9bb50ab5570653ad966e3ca5f1ef9aca74771fc40d988f
7
+ data.tar.gz: 45d1c2deda36455ffae69d4b6932b4a6e13fef49398a73ab8d8b2784b8d28317bf9a3c82af5c881c1f334f823e019efd1d9a7fb964d899fc7d2897f3a7021d3a
data/README.md CHANGED
@@ -24,8 +24,10 @@ $ gem install himekaminize
24
24
 
25
25
  ## Usage
26
26
 
27
- ```
28
- Himekaminize::TaskList.new("- [ ] TODO\n - [ ] ねる\n - [ ] おきる").to_a
27
+ ```ruby
28
+ task_list = Himekaminize::TaskList.new("- [ ] TODO\n - [ ] ねる\n - [ ] おきる").call
29
+
30
+ task_list.update_task_status(1, :complete)
29
31
  ```
30
32
 
31
33
  ## Development
@@ -7,12 +7,18 @@ module Himekaminize
7
7
  def initialize(markdown)
8
8
  @markdown = markdown
9
9
  to_lines
10
+ @result ||= Hash.new
10
11
  end
11
12
 
12
- def to_a
13
- filters.inject(lines) do |result, filter|
14
- filter.call(result)
15
- end
13
+ def call
14
+ result[:output] =
15
+ filters.inject(lines) do |output, filter|
16
+ filter.call(output)
17
+ end
18
+ end
19
+
20
+ def result
21
+ @result
16
22
  end
17
23
 
18
24
  private
@@ -3,23 +3,31 @@ module Himekaminize
3
3
  INCOMPLETE_PATTERN = /[-+*]\s\[\s\]\s/
4
4
  COMPLETE_PATTERN = /[-+*]\s\[[xX]\]\s/
5
5
 
6
+ INCOMPLETE_MD = '- [ ]'.freeze
7
+ COMPLETE_MD = '- [x]'.freeze
6
8
  attr_accessor :name, :status, :sequence
7
9
 
8
10
  COMPLETE_STATUSE = :complete
9
11
  INCOMPLETE_STATUSE = :incomplete
12
+ STATUSES = %I(#{COMPLETE_STATUSE} #{INCOMPLETE_STATUSE})
10
13
 
11
14
  def initialize(line, sequence)
12
15
  @sequence = sequence
13
- @status, @name = split_name_and_status(line)
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", @space, status_str, @name)
14
22
  end
15
23
 
16
24
  private
17
25
  def split_name_and_status(line)
18
- /\A\s*(#{INCOMPLETE_PATTERN}|#{COMPLETE_PATTERN})(.*)/.match(line) do |m|
19
- if m[1] =~ /#{INCOMPLETE_PATTERN}/
20
- return [INCOMPLETE_STATUSE, m[2]]
26
+ /\A(\s)*(#{INCOMPLETE_PATTERN}|#{COMPLETE_PATTERN})(.*)/.match(line) do |m|
27
+ if m[2] =~ /#{INCOMPLETE_PATTERN}/
28
+ return [INCOMPLETE_STATUSE, m[3], m[1]]
21
29
  else
22
- return [COMPLETE_STATUSE, m[2]]
30
+ return [COMPLETE_STATUSE, m[3], m[1]]
23
31
  end
24
32
  end
25
33
  end
@@ -1,3 +1,4 @@
1
+ require "active_support/core_ext/object"
1
2
  module Himekaminize
2
3
  class TaskList
3
4
  include ::Himekaminize::Filterable
@@ -11,16 +12,27 @@ module Himekaminize
11
12
  end
12
13
 
13
14
  def to_task_list
14
- array = to_a
15
- array.select { |line| line.is_a?(Himekaminize::Task) }
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
16
28
  end
17
29
 
18
30
  def to_s
19
- array = to_a
31
+ array = result.try(:output) || call
20
32
  seq = 0
21
33
  array.map do |line|
22
- if line.is_a?(Himekaminize::Task)
23
- Himekaminize::Task.new(line, seq)
34
+ if line.is_a?(::Himekaminize::Task)
35
+ line.to_s
24
36
  else
25
37
  line
26
38
  end
@@ -1,3 +1,3 @@
1
1
  module Himekaminize
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
4
+ version: 0.0.3
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-05 00:00:00.000000000 Z
11
+ date: 2017-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport