nbf_tools 0.2.1 → 0.3.0

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
  SHA256:
3
- metadata.gz: 885abc5c5af24a8ee6d9d08d83ca302291b14e868684742404f10116c2983b19
4
- data.tar.gz: 4806b463cccf40009c29c9ff3d8508a0920dd5a1f91a2f30ab430713f345f4cf
3
+ metadata.gz: de5e17d1820e018c6dc5e9af02592540a633f591d394f379e3728c1a8895195d
4
+ data.tar.gz: 0f41f05769c1e740f56e44ca316604b8aaf485852659c9b661cbb8f86013ee6a
5
5
  SHA512:
6
- metadata.gz: 4c5d27b869913b81e7766544bb033fbf1b5290ff655855e29e608644e27231cf4817b628c80f747afb9bc15bcfde2d14ad1e55b36ab82a4ac7f21fc460379830
7
- data.tar.gz: 9765ee19f410e561f083cf754bace377a99f63ad2c30deb072c6caafab40beac993f8f2258352d17f9fdb05f241975751ea1ec4fa99220495f5df8f6b798ed66
6
+ metadata.gz: 84ff37f2ae40c766b750c0e731bc29f03beb714ba761d0149d379ff2bd1d0798637a8f5888853ef32a5264ada0e83e1d8e329bce48f1fd9c23f6ce94c8127c62
7
+ data.tar.gz: 04b1eda848f324e4e138ef40d8eccd4f60f1556f122b573801a47ce6a2d19d302baa0407bca79b08d24e776748e34225bf88b87ec5089c0940f8342fafc1f0ad
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # [Changelog]
2
2
 
3
+ ## [0.3.0] - 2023-10-21
4
+
5
+ - feat: implement command line tools haha `nbf_tools`
6
+
7
+ ## [0.2.1] - 2023-10-11
8
+
9
+ - doc: quote CHANGELOG.md method name
10
+
3
11
  ## [0.2.0] - 2023-10-11
4
12
 
5
13
  - feat: Reomve configuration, add parse options
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nbf_tools (0.2.1)
4
+ nbf_tools (0.3.0)
5
5
  nokogiri (~> 1.15)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # NbfTools
2
2
 
3
- NETSCAPE Bookmark file tools,file from chrome edge firefox safari browser
3
+ NETSCAPE Bookmark file tools, parse and merge multiple files.
4
+
5
+ The file was exported from Chrome, Edge, Firefox or Safari browser.
4
6
 
5
7
  ## Installation
6
8
 
@@ -14,27 +16,63 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
16
 
15
17
  ## Usage
16
18
 
17
- Parse NETSCAPE Bookmark file.
19
+ ### Command
18
20
 
19
- ```ruby
20
- NbfTools.parse bookmark_file_path
21
+ Help.
22
+
23
+ ```sh
24
+ usage: nbf_tools [options]
25
+ -f, --files NETSCAPE Bookmark files, delimit by space
26
+ -o, --out-format output parse result format (default: html), options: json, html
27
+ -t, --personal-toolbar-folder-text custom personal toolbar folder text
28
+
29
+ other options:
30
+ -h, --help print help
31
+ -v, --version print version
21
32
  ```
22
33
 
23
- Merge and parse multiple NETSCAPE Bookmark files.
34
+ Example.
24
35
 
25
- ```ruby
26
- NbfTools.parse_files_to_one bookmark_file_path1, bookmark_file_path2
36
+ ```sh
37
+ # print merged json
38
+ nbf_tools -f bk2.html bk1.html -o json
39
+
40
+ # save merged new html file
41
+ nbf_tools -f bk2.html bk1.html -o json > bk.html
27
42
  ```
28
43
 
29
- Merge multiple NETSCAPE Bookmark files into one html string.
44
+ ### Code
45
+
46
+ Example.
30
47
 
31
48
  ```ruby
32
- NbfTools.merge_files_to_one_html bookmark_file_path1, bookmark_file_path2
49
+ require "nbf_tools"
50
+
51
+ # parse file
52
+ # options: `{personal_toolbar_folder_text: "some string"}`, is optional
53
+ NbfTools.parse "bk2.html"
54
+
55
+ # merge and parse multiple files
56
+ # options: `{personal_toolbar_folder_text: "some string"}`, is optional
57
+ NbfTools.parse_files_to_one "bk1.html", "bk2.html", personal_toolbar_folder_text: "bk"
58
+
59
+ # merge multiple files into one html string
60
+ # options: `{personal_toolbar_folder_text: "some string"}`, is optional
61
+ NbfTools.merge_files_to_one_html "bk1.html", "bk2.html"
62
+
63
+ # parse and merge operate with options
64
+ # options: `{files: [], personal_toolbar_folder_text: [], out_format: []}`
65
+ # `:files` must present
66
+ # `:personal_toolbar_folder_text` is optional
67
+ # if `:out_format` is `"json"` return json format else retrun return html format
68
+ NbfTools.merge_files_to_one_html(files: %w[bk1.html bk2.html], personal_toolbar_folder_text: [], out_format: %w[json])
33
69
  ```
34
70
 
35
71
  ## Development
36
72
 
37
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+ After checking out the repo, run `bin/setup` to install dependencies.
74
+ Then, run `rake test` to run the tests.
75
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
76
 
39
77
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
78
 
data/exe/nbf_tools ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $stdout.sync = true
5
+
6
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
7
+
8
+ require "nbf_tools"
9
+
10
+ puts NbfTools.operate_with_options(NbfTools::Options.new(ARGV).parse)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NbfTools
4
+ class Options
5
+ COMMAND_HELP_TEXT = <<~TEXT.chomp
6
+ usage: nbf_tools [options]
7
+ -f, --files NETSCAPE Bookmark files, delimit by space
8
+ -o, --out-format output parse result format (default: html), options: json, html
9
+ -t, --personal-toolbar-folder-text custom personal toolbar folder text
10
+
11
+ other options:
12
+ -h, --help print help
13
+ -v, --version print version
14
+ TEXT
15
+
16
+ def initialize(argv)
17
+ @argv = argv
18
+ end
19
+
20
+ def parse
21
+ opts = {unknown_option: [], files: [], personal_toolbar_folder_text: [], out_format: []}
22
+ option_key = :unknown_option
23
+
24
+ @argv.each do |e|
25
+ case e
26
+ when "-h", "--help"
27
+ puts COMMAND_HELP_TEXT
28
+ exit
29
+ when "-v", "--version"
30
+ puts NbfTools::VERSION
31
+ exit
32
+ when "-f", "--files"
33
+ option_key = :files
34
+ when "-o", "--out_format"
35
+ option_key = :out_format
36
+ when "-t", "--personal_toolbar_folder_text"
37
+ option_key = :personal_toolbar_folder_text
38
+ when /\A-.+\z/
39
+ option_key = :unknown_option
40
+ warn "unknown option #{e}"
41
+ else
42
+ opts[option_key] << e
43
+ end
44
+ end
45
+
46
+ opts
47
+ end
48
+ end
49
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module NbfTools::Type
4
- LINK = "link"
5
- FOLDER = "folder"
3
+ module NbfTools
4
+ module Type
5
+ LINK = "link"
6
+ FOLDER = "folder"
7
+ end
6
8
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NbfTools
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/nbf_tools.rb CHANGED
@@ -3,16 +3,24 @@
3
3
  require_relative "nbf_tools/html"
4
4
  require_relative "nbf_tools/merge"
5
5
  require_relative "nbf_tools/parse"
6
+ require_relative "nbf_tools/options"
6
7
  require_relative "nbf_tools/version"
7
8
 
9
+ require "json"
10
+
8
11
  module NbfTools
9
12
  class Error < StandardError; end
10
13
 
11
14
  class << self
15
+
16
+ # parse file
17
+ # options: `{personal_toolbar_folder_text: "some string"}`, is optional
12
18
  def parse(file, **options)
13
19
  Parse.new(**options).parse(file)
14
20
  end
15
21
 
22
+ # merge and parse multiple files
23
+ # options: `{personal_toolbar_folder_text: "some string"}`, is optional
16
24
  def parse_files_to_one(*files, **options)
17
25
  parse_tool = Parse.new(**options)
18
26
  data = files.map { |file| parse_tool.parse(file) }
@@ -20,10 +28,27 @@ module NbfTools
20
28
  Merge.new(data).to_a
21
29
  end
22
30
 
23
- def merge_files_to_one_html(*files, **custom_options)
31
+ # merge multiple files into one html string
32
+ # options: `{personal_toolbar_folder_text: "some string"}`, is optional
33
+ def merge_files_to_one_html(*files, **options)
24
34
  return File.read(files[0]) if files.size < 2
25
- data = parse_files_to_one(*files)
35
+ data = parse_files_to_one(*files, **options)
26
36
  HTML.new(data).to_s
27
37
  end
38
+
39
+ # parse and merge operate with options
40
+ # options: `{files: [], personal_toolbar_folder_text: [], out_format: []}`
41
+ # `:files` must present
42
+ # `:personal_toolbar_folder_text` is optional
43
+ # if `:out_format` is `"json"` return json format else retrun return html format
44
+ def operate_with_options(opts)
45
+ opts[:out_format] ||= []
46
+ opts[:personal_toolbar_folder_text] = [opts[:personal_toolbar_folder_text]] if opts[:personal_toolbar_folder_text].is_a?(Array)
47
+ if opts[:out_format].join(" ") == "json"
48
+ parse_files_to_one(*opts[:files], personal_toolbar_folder_text: opts[:personal_toolbar_folder_text].join(" ")).to_json
49
+ else
50
+ merge_files_to_one_html(*opts[:files], personal_toolbar_folder_text: opts[:personal_toolbar_folder_text].join(" "))
51
+ end
52
+ end
28
53
  end
29
54
  end
data/nbf_tools.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Sapeu"]
9
9
  spec.email = ["sapeu.lee@foxmail.com"]
10
10
 
11
- spec.summary = "NETSCAPE Bookmark file tools."
12
- spec.description = "NETSCAPE Bookmark file tools."
11
+ spec.summary = "NETSCAPE Bookmark file tools, parse and merge multiple files."
12
+ spec.description = "NETSCAPE Bookmark file tools, parse file and merge multiple files.\nThe file was exported from Chrome, Edge, Firefox or Safari browser."
13
13
  spec.homepage = "https://github.com/sapeu/nbf_tools"
14
14
  spec.required_ruby_version = ">= 2.7.0"
15
15
  spec.license = "MIT"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nbf_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sapeu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2023-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -38,10 +38,13 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.31'
41
- description: NETSCAPE Bookmark file tools.
41
+ description: |-
42
+ NETSCAPE Bookmark file tools, parse file and merge multiple files.
43
+ The file was exported from Chrome, Edge, Firefox or Safari browser.
42
44
  email:
43
45
  - sapeu.lee@foxmail.com
44
- executables: []
46
+ executables:
47
+ - nbf_tools
45
48
  extensions: []
46
49
  extra_rdoc_files: []
47
50
  files:
@@ -51,9 +54,11 @@ files:
51
54
  - Gemfile.lock
52
55
  - README.md
53
56
  - Rakefile
57
+ - exe/nbf_tools
54
58
  - lib/nbf_tools.rb
55
59
  - lib/nbf_tools/html.rb
56
60
  - lib/nbf_tools/merge.rb
61
+ - lib/nbf_tools/options.rb
57
62
  - lib/nbf_tools/parse.rb
58
63
  - lib/nbf_tools/type.rb
59
64
  - lib/nbf_tools/version.rb
@@ -84,5 +89,5 @@ requirements: []
84
89
  rubygems_version: 3.4.10
85
90
  signing_key:
86
91
  specification_version: 4
87
- summary: NETSCAPE Bookmark file tools.
92
+ summary: NETSCAPE Bookmark file tools, parse and merge multiple files.
88
93
  test_files: []