arbolobra 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +10 -0
- data/arbolobra.gemspec +38 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/arbolobra.rb +5 -0
- data/lib/arbolobra/chars.rb +82 -0
- data/lib/arbolobra/node.rb +41 -0
- data/lib/arbolobra/tree.rb +36 -0
- data/lib/arbolobra/version.rb +3 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a7d8757dacdbea1f3bd516605a4fa635b3761dc
|
4
|
+
data.tar.gz: f30750650c66f8d727a2232e8ac907efe903ab7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d09963fc27a25a29662a4477b7fe524013e64b6bb13aa3474f47ef286f3f200d5bbbb987d10c36a966b81a288def7166faa5762e38194572d6d7c80260f72536
|
7
|
+
data.tar.gz: f4ff880e0e3f04557033d7896b5f311de51ed0357ee264f5ace9857519330903529476c15b02791a5fb11154343b07e0837482eeee69d3f41f08a08cb2b792d9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jeff Pace
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jeff Pace
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Arbolobra
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up
|
4
|
+
your Ruby library into a gem. Put your Ruby code in the file `lib/arbolobra`. To experiment with
|
5
|
+
that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
TODO: Delete this and the text above, and describe your gem
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'arbolobra'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install arbolobra
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Arbolobra is for reading and writing a hierarchical set of data, i.e., a tree.
|
28
|
+
|
29
|
+
For example, a simple viewer of files and directories, as a tree:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
def build pn
|
33
|
+
children = pn.directory? ? pn.children.sort : Array.new
|
34
|
+
Arbolobra::Node.new pn.basename, children.collect { |child| build child }
|
35
|
+
end
|
36
|
+
|
37
|
+
args = ARGV.empty? ? %w{ . } : ARGV
|
38
|
+
|
39
|
+
args.each do |arg|
|
40
|
+
pn = Pathname.new arg
|
41
|
+
node = build pn
|
42
|
+
|
43
|
+
node.print
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
And to change output, such as from a list of files, from flat to hierarchical:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
tree = Arbolobra::Tree.new $stdin.readlines, "/"
|
51
|
+
tree.root.print
|
52
|
+
```
|
53
|
+
|
54
|
+
```shell
|
55
|
+
% git diff-index --name-only --no-commit-id <commit> | <above script>
|
56
|
+
```
|
57
|
+
|
58
|
+
```text
|
59
|
+
|
60
|
+
+---.gitignore
|
61
|
+
+---README.md
|
62
|
+
+---lib
|
63
|
+
| \---arbolobra
|
64
|
+
| +---chars.rb
|
65
|
+
| +---node.rb
|
66
|
+
| \---tree.rb
|
67
|
+
\---test
|
68
|
+
\---arbolobra
|
69
|
+
+---chars_test.rb
|
70
|
+
+---node_test.rb
|
71
|
+
\---tree_test.rb
|
72
|
+
```
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run
|
77
|
+
the tests. You can also run `bin/console` for an interactive prompt that will allow you to
|
78
|
+
experiment.
|
79
|
+
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
81
|
+
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
82
|
+
will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
83
|
+
[rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jpace/arbolobra.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/arbolobra.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "arbolobra/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arbolobra"
|
8
|
+
spec.version = Arbolobra::VERSION
|
9
|
+
spec.authors = ["Jeff Pace"]
|
10
|
+
spec.email = ["jeugenepace@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Reads and writes a tree.}
|
13
|
+
spec.description = %q{Converts flat output to a hierarchy, and outputs with nested sections.}
|
14
|
+
spec.homepage = "http://www.github.com/jpace/arbolobra"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "test-unit", "~> 3.1"
|
36
|
+
spec.add_development_dependency "paramesan", "~> 0.1.1"
|
37
|
+
spec.add_development_dependency "logue", "~> 1.0"
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "arbolobra"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/arbolobra.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
module Arbolobra
|
5
|
+
end
|
6
|
+
|
7
|
+
# this looks like:
|
8
|
+
|
9
|
+
# | +---packed-refs
|
10
|
+
# | \---refs
|
11
|
+
# | +---heads
|
12
|
+
# | | +---add-node
|
13
|
+
# | | \---master
|
14
|
+
# | +---remotes
|
15
|
+
# | | \---origin
|
16
|
+
# | | +---HEAD
|
17
|
+
# | | \---master
|
18
|
+
# | \---tags
|
19
|
+
|
20
|
+
# \---test
|
21
|
+
# x +---arbolobra
|
22
|
+
# x | +---chars_test.rb
|
23
|
+
# x | +---node_test.rb
|
24
|
+
# x | \---tree_test.rb
|
25
|
+
# x +---arbolobra_test.rb
|
26
|
+
# x \---test_helper.rb
|
27
|
+
|
28
|
+
|
29
|
+
# this is the "intro" (i) and the "lead" (l):
|
30
|
+
# <iiiiii><ll>
|
31
|
+
# x | +---node_test.rb
|
32
|
+
# x | \---tree_test.rb
|
33
|
+
|
34
|
+
# +---abc
|
35
|
+
# |yyy+---def
|
36
|
+
# |yyy|yyy+---ghi
|
37
|
+
# |yyy|yyy\---jkl
|
38
|
+
# |yyy\---ghi
|
39
|
+
# +---def
|
40
|
+
# |yyy\---ghi
|
41
|
+
# |yyyxyyy+---2
|
42
|
+
# |yyyxyyy\---3
|
43
|
+
# \---abc
|
44
|
+
# xyyy\---mno
|
45
|
+
|
46
|
+
# in intro:
|
47
|
+
# | - down to next
|
48
|
+
# x - down from last (default is space, not x)
|
49
|
+
# y - gap to child (default is space, not y)
|
50
|
+
|
51
|
+
# in lead:
|
52
|
+
# + - marker to child
|
53
|
+
# \ - marker to last
|
54
|
+
# - - over to child
|
55
|
+
|
56
|
+
class Arbolobra::CharList
|
57
|
+
def initialize chars, width: 4
|
58
|
+
@chars = chars
|
59
|
+
@width = width
|
60
|
+
end
|
61
|
+
|
62
|
+
def expand is_last
|
63
|
+
leftchr = @chars[is_last ? 0 : 1]
|
64
|
+
repeatchr = @chars[2]
|
65
|
+
leftchr + repeatchr * (@width - 1)
|
66
|
+
end
|
67
|
+
|
68
|
+
DEFAULT_INTRO = new [ ' ', '|', ' ' ]
|
69
|
+
DEFAULT_LEAD = new [ '\\', '+', '-' ]
|
70
|
+
end
|
71
|
+
|
72
|
+
class Arbolobra::CharSet
|
73
|
+
attr_reader :intro
|
74
|
+
attr_reader :lead
|
75
|
+
|
76
|
+
def initialize intro, lead
|
77
|
+
@intro = intro
|
78
|
+
@lead = lead
|
79
|
+
end
|
80
|
+
|
81
|
+
DEFAULT = new Arbolobra::CharList::DEFAULT_INTRO, Arbolobra::CharList::DEFAULT_LEAD
|
82
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'arbolobra/chars'
|
5
|
+
|
6
|
+
module Arbolobra
|
7
|
+
end
|
8
|
+
|
9
|
+
class Arbolobra::Node
|
10
|
+
include Comparable
|
11
|
+
|
12
|
+
attr_reader :value
|
13
|
+
attr_reader :children
|
14
|
+
|
15
|
+
def initialize value, children = Array.new
|
16
|
+
@value = value
|
17
|
+
@children = children
|
18
|
+
end
|
19
|
+
|
20
|
+
def print intro: "", lead: "", output: $stdout, chars: Arbolobra::CharSet::DEFAULT
|
21
|
+
output.print lead, @value.to_s, "\n"
|
22
|
+
childargs = { intro: intro, output: output, chars: chars }
|
23
|
+
@children.each_with_index do |child, idx|
|
24
|
+
print_child child, childargs.merge({ is_last: idx == @children.size - 1 })
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_child child, intro: "", is_last: false, output: $stdout, chars: Arbolobra::CharSet::DEFAULT
|
29
|
+
nextintro = intro + chars.intro.expand(is_last)
|
30
|
+
nextlead = intro + chars.lead.expand(is_last)
|
31
|
+
child.print intro: nextintro, lead: nextlead, output: output, chars: chars
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
@value
|
36
|
+
end
|
37
|
+
|
38
|
+
def <=> other
|
39
|
+
value <=> other.value && children <=> other.children
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'arbolobra/node'
|
5
|
+
|
6
|
+
module Arbolobra
|
7
|
+
end
|
8
|
+
|
9
|
+
class Arbolobra::Tree
|
10
|
+
attr_reader :root
|
11
|
+
attr_reader :nodes
|
12
|
+
|
13
|
+
def initialize lines, separator
|
14
|
+
raise "lines argument requires a separator" unless separator
|
15
|
+
@root = Arbolobra::Node.new nil
|
16
|
+
|
17
|
+
lines.each do |line|
|
18
|
+
elements = line.chomp.split separator
|
19
|
+
create_nodes elements
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_nodes elements
|
24
|
+
node = @root
|
25
|
+
elements.each do |elmt|
|
26
|
+
subnode = node.children[-1]
|
27
|
+
if subnode && subnode.value == elmt
|
28
|
+
node = subnode
|
29
|
+
else
|
30
|
+
newnode = Arbolobra::Node.new elmt
|
31
|
+
node.children << newnode
|
32
|
+
node = newnode
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arbolobra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Pace
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: paramesan
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: logue
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description: Converts flat output to a hierarchy, and outputs with nested sections.
|
84
|
+
email:
|
85
|
+
- jeugenepace@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- arbolobra.gemspec
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/arbolobra.rb
|
101
|
+
- lib/arbolobra/chars.rb
|
102
|
+
- lib/arbolobra/node.rb
|
103
|
+
- lib/arbolobra/tree.rb
|
104
|
+
- lib/arbolobra/version.rb
|
105
|
+
homepage: http://www.github.com/jpace/arbolobra
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata:
|
109
|
+
allowed_push_host: https://rubygems.org
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.6.3
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Reads and writes a tree.
|
130
|
+
test_files: []
|