booklab-toc 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 112b117e599d6b18e064fcd17a06e3c6981c56c6d2373471eec7a073946baf03
4
- data.tar.gz: 36ea1bac90ca58f3ed16297e41054edd576a11d7e064b61dd2a088c5be584408
3
+ metadata.gz: 5dcff03faea9255ce3e885606b9e3525424ca713c68c4f95e243118744222dc3
4
+ data.tar.gz: 9b4a848863736348b8eb7b13912eb79640592146595fb97e4ad67d5fabed5685
5
5
  SHA512:
6
- metadata.gz: ae829cd9b40fada469f54a2c3df33423ec04b3c74022fc978486f38a43e1f483fa2065c8a7fe46658909375627df31a536128ebb73db8aec6c00f58c5335e8b0
7
- data.tar.gz: 48e65eaf8b50db91e27c700ab7b73049f95e1c4b786bf31f9d27b62c4e57e8ef95b24025e53a2bb24b378f11f2d8dd93fd2546d90c48b4f130630a9ab45dd0fc
6
+ metadata.gz: 28d3a4fa6ebc7b55d0aea9d46bf7db5e861c6ad9f9a14841c261e404a02eb77871ed25c9bddce8ac53e6c597e144b4c13410ebe25a449f19e7ef1ef2f3f8e38e
7
+ data.tar.gz: 404e6d25c860389a251015b6ca2568c92cca598214fadae1381e40f0a48ba0ce702562f99079c93800cd07aa6d30a9ed95dd5d7e288693e58255b1bd38f132f9
@@ -1,5 +1,5 @@
1
1
  module BookLab
2
2
  module Toc
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
data/lib/booklab-toc.rb CHANGED
@@ -5,28 +5,37 @@ require "booklab/toc/format/markdown"
5
5
 
6
6
  module BookLab
7
7
  module Toc
8
+ class FormatError < Exception; end
9
+
8
10
  extend ActiveSupport::Autoload
9
11
 
12
+ class << self
13
+ delegate :logger, to: Rails
10
14
 
11
- def self.parse(raw, format: :yml)
12
- items = []
13
- datas = []
15
+ def parse(raw, format: :yml, strict: false)
16
+ items = []
17
+ datas = []
14
18
 
15
- case format
16
- when :yml
17
- datas = YAML.load(raw)
18
- when :json
19
- datas = JSON.load(raw)
20
- when :markdown
21
- datas = Format::Markdown.load(raw)
22
- else
23
- raise "format: #{format} not implement"
24
- end
19
+ case format
20
+ when :yml
21
+ datas = YAML.load(raw)
22
+ when :json
23
+ datas = JSON.load(raw)
24
+ when :markdown
25
+ datas = Format::Markdown.load(raw)
26
+ else
27
+ raise "format: #{format} not implement"
28
+ end
25
29
 
26
- datas.each do |obj|
27
- items << ListItem.new(title: obj["title"], url: obj["url"], depth: obj["depth"], id: obj["id"])
30
+ datas.each do |obj|
31
+ items << ListItem.new(obj.to_hash.deep_symbolize_keys)
32
+ end
33
+ Content.new(items)
34
+ rescue => e
35
+ raise FormatError.new(e.message) if strict
36
+ logger.warn "BookLab::Toc.parse error:\n#{e.inspect}"
37
+ Content.new([])
28
38
  end
29
- Content.new(items)
30
39
  end
31
40
  end
32
- end
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: booklab-toc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-29 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails