bblib 0.4.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -11
- data/.rspec +2 -2
- data/.travis.yml +4 -4
- data/CODE_OF_CONDUCT.md +13 -13
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/Rakefile +6 -6
- data/bblib.gemspec +34 -34
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/lib/array/bbarray.rb +2 -2
- data/lib/bblib.rb +1 -0
- data/lib/bblib/version.rb +1 -1
- data/lib/class/effortless.rb +2 -2
- data/lib/file/bbfile.rb +10 -8
- data/lib/hash/bbhash.rb +23 -15
- data/lib/hash/hash_struct.rb +1 -1
- data/lib/hash/tree_hash.rb +1 -1
- data/lib/hash_path/hash_path.rb +3 -3
- data/lib/hash_path/part.rb +2 -2
- data/lib/html/bbhtml.rb +1 -0
- data/lib/html/builder.rb +15 -6
- data/lib/html/tag.rb +74 -5
- data/lib/html/tag_set.rb +20 -0
- data/lib/logging/bblogging.rb +2 -1
- data/lib/mixins/attrs.rb +40 -25
- data/lib/mixins/bbmixins.rb +2 -0
- data/lib/mixins/family_tree.rb +12 -0
- data/lib/mixins/hooks.rb +8 -1
- data/lib/mixins/logger.rb +10 -10
- data/lib/mixins/prototype.rb +26 -0
- data/lib/mixins/simple_init.rb +47 -17
- data/lib/mixins/type_init.rb +21 -0
- data/lib/number/bbnumber.rb +90 -0
- data/lib/object/bbobject.rb +1 -5
- data/lib/opal/bbopal.rb +5 -0
- data/lib/os/bbos.rb +0 -63
- data/lib/string/bbstring.rb +22 -1
- data/lib/string/cases.rb +4 -4
- data/lib/time/bbtime.rb +27 -0
- data/lib/time/task_timer.rb +3 -1
- metadata +4 -2
- data/lib/os/bbsys.rb +0 -255
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8de738293171e9bdf15bf8b494cc55fb4353b088c01219df302b886218ad1176
|
4
|
+
data.tar.gz: 5623dacf641eed1205a0c2ed76919d3e2d1c56cea40f1c7270e965104d41f25e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 425b7aaa6a8d5a736ab0d89604828f9918c444b2895d7f3174939a884f7964ab6d6b510e9575d1483a5b573c8308e5921f723cb46704578df85f866da4512f88
|
7
|
+
data.tar.gz: f55d3693b96705cedf0a376eb3bc7f8df1102a2f4b1efeb90f4c9832a24a5b216719122b4de4a61d412ad3ce9a76fba79c8c22c4ed11ca3f640fc3ff0a6887e2
|
data/.gitignore
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
|
11
|
-
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/spec/coverage/
|
11
|
+
*.gem
|
12
|
+
smells.html
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
1
|
+
--format documentation
|
2
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.6
|
4
|
-
before_install: gem install bundler -v 1.10.6
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.6
|
4
|
+
before_install: gem install bundler -v 1.10.6
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in bblib.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in bblib.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 Brandon
|
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.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Brandon
|
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/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
data/bblib.gemspec
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'bblib/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "bblib"
|
8
|
-
spec.version = BBLib::VERSION
|
9
|
-
spec.authors = ["Brandon Black"]
|
10
|
-
spec.email = ["d2sm10@hotmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{A library containing many reusable, basic functions.}
|
13
|
-
spec.description = %q{A library containing many reusable, basic functions.}
|
14
|
-
spec.homepage = "https://github.com/bblack16/bblib-ruby"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.end_with?('.gem') }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "rspec"
|
33
|
-
spec.add_development_dependency "simplecov"
|
34
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bblib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bblib"
|
8
|
+
spec.version = BBLib::VERSION
|
9
|
+
spec.authors = ["Brandon Black"]
|
10
|
+
spec.email = ["d2sm10@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A library containing many reusable, basic functions.}
|
13
|
+
spec.description = %q{A library containing many reusable, basic functions.}
|
14
|
+
spec.homepage = "https://github.com/bblack16/bblib-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.end_with?('.gem') }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "simplecov"
|
34
|
+
end
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "bblib"
|
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
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bblib"
|
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
|
data/bin/setup
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
bundle install
|
6
|
-
|
7
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
# Do any other automated setup that you need to do here
|
data/lib/array/bbarray.rb
CHANGED
@@ -29,7 +29,7 @@ module BBLib
|
|
29
29
|
# Takes an array and averages all of the floats and integers within it.
|
30
30
|
# Non numeric values are ignored.
|
31
31
|
def self.average(ary)
|
32
|
-
numbers = ary.select { |v| BBLib.
|
32
|
+
numbers = ary.select { |v| BBLib.is_any?(v, Integer, Float) }
|
33
33
|
numbers.inject(0) do |sum, x|
|
34
34
|
sum += x
|
35
35
|
end / numbers.size.to_f
|
@@ -87,6 +87,6 @@ class Array
|
|
87
87
|
|
88
88
|
def hmap
|
89
89
|
return map unless block_given?
|
90
|
-
map { |v| yield(v) }.to_h
|
90
|
+
map { |v| yield(v) }.compact.to_h
|
91
91
|
end
|
92
92
|
end
|
data/lib/bblib.rb
CHANGED
data/lib/bblib/version.rb
CHANGED
data/lib/class/effortless.rb
CHANGED
@@ -5,11 +5,11 @@ module BBLib
|
|
5
5
|
base.extend(BBLib::Attrs)
|
6
6
|
base.extend(BBLib::Hooks)
|
7
7
|
base.singleton_class.extend(BBLib::Hooks)
|
8
|
-
base.extend(BBLib::FamilyTree)
|
8
|
+
base.extend(BBLib::FamilyTree)
|
9
9
|
base.extend(BBLib::Bridge)
|
10
|
+
base.send(:include, BBLib::Logger)
|
10
11
|
base.send(:include, BBLib::Serializer)
|
11
12
|
base.send(:include, BBLib::SimpleInit)
|
12
|
-
base.send(:include, BBLib::Logger)
|
13
13
|
end
|
14
14
|
|
15
15
|
def _attrs
|
data/lib/file/bbfile.rb
CHANGED
@@ -3,7 +3,7 @@ module BBLib
|
|
3
3
|
# Takes one or more strings and normalizes slashes to create a consistent file path
|
4
4
|
# Useful when concating two strings that when you don't know if one or both will end or begin with a slash
|
5
5
|
def self.pathify(*strings)
|
6
|
-
(strings.first.start_with?('/', '\\') ?
|
6
|
+
(strings.first.start_with?('/', '\\') ? strings.first.scan(/^[\/\\]{1,2}/).first : '') + strings.map(&:to_s).msplit('/', '\\').map(&:strip).join('/')
|
7
7
|
end
|
8
8
|
|
9
9
|
# Scan for files and directories. Can be set to be recursive and can also have filters applied.
|
@@ -13,18 +13,20 @@ module BBLib
|
|
13
13
|
# @param [Boolean] recursive When true scan will recursively search directories
|
14
14
|
# @param [Boolean] files If true, paths to files matching the filter will be returned.
|
15
15
|
# @param [Boolean] dirs If true, paths to dirs matching the filter will be returned.
|
16
|
-
|
16
|
+
# @param [Array] exclude Can be an array of regular expressions or strings that should be ignored when scanning. * in a string is expanded into .*, but all other characters are literal.
|
17
|
+
def self.scan_dir(path, *filters, recursive: false, files: true, dirs: true, exclude: [], &block)
|
17
18
|
return [] unless Dir.exist?(path)
|
18
19
|
filters = filters.map { |filter| filter.is_a?(Regexp) ? filter : /^#{Regexp.quote(filter).gsub('\\*', '.*')}$/ }
|
20
|
+
exclude = exclude ? [exclude].flatten.map { |exp| exp.is_a?(Regexp) ? exp : /^#{Regexp.quote(exp).gsub('\\*', '.*')}$/ } : []
|
19
21
|
Dir.foreach(path).flat_map do |item|
|
20
|
-
next if item =~ /^\.{1,2}$/
|
22
|
+
next if item =~ /^\.{1,2}$/ || (!exclude.empty? && exclude.any? { |exp| item =~ exp })
|
21
23
|
item = "#{path}/#{item}".gsub('\\', '/')
|
22
24
|
if File.file?(item)
|
23
25
|
if files && (filters.empty? || filters.any? { |filter| item =~ filter })
|
24
26
|
block_given? ? yield(item) : item
|
25
27
|
end
|
26
28
|
elsif File.directory?(item)
|
27
|
-
recur = recursive ? scan_dir(item, *filters, recursive: recursive, files: files, dirs: dirs, &block) : []
|
29
|
+
recur = recursive ? scan_dir(item, *filters, recursive: recursive, exclude: exclude, files: files, dirs: dirs, &block) : []
|
28
30
|
if dirs && (filters.empty? || filters.any? { |filter| item =~ filter })
|
29
31
|
(block_given? ? yield(item) : [item] + recur)
|
30
32
|
elsif recursive
|
@@ -35,13 +37,13 @@ module BBLib
|
|
35
37
|
end
|
36
38
|
|
37
39
|
# Uses BBLib.scan_dir but returns only files
|
38
|
-
def self.scan_files(path, *filters, recursive: false, &block)
|
39
|
-
scan_dir(path, *filters, recursive: recursive, dirs: false, &block)
|
40
|
+
def self.scan_files(path, *filters, recursive: false, exclude: [], &block)
|
41
|
+
scan_dir(path, *filters, recursive: recursive, dirs: false, exclude: exclude, &block)
|
40
42
|
end
|
41
43
|
|
42
44
|
# Uses BBLib.scan_dir but returns only directories.
|
43
|
-
def self.scan_dirs(path, *filters, recursive: false, &block)
|
44
|
-
scan_dir(path, *filters, recursive: recursive, files: false, &block)
|
45
|
+
def self.scan_dirs(path, *filters, recursive: false, exclude: [], &block)
|
46
|
+
scan_dir(path, *filters, recursive: recursive, files: false, exclude: exclude, &block)
|
45
47
|
end
|
46
48
|
|
47
49
|
# Shorthand method to write a string to disk. By default the
|
data/lib/hash/bbhash.rb
CHANGED
@@ -83,22 +83,30 @@ class Hash
|
|
83
83
|
def path_nav(obj, path = '', delimiter = '.', &block)
|
84
84
|
case obj
|
85
85
|
when Hash
|
86
|
-
obj.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
86
|
+
if obj.empty?
|
87
|
+
yield path, obj
|
88
|
+
else
|
89
|
+
obj.each do |k, v|
|
90
|
+
path_nav(
|
91
|
+
v,
|
92
|
+
(path ? [path, k.to_s.gsub(delimiter, "\\#{delimiter}")].join(delimiter) : k.to_s.gsub(delimiter, "\\#{delimiter}")).to_s,
|
93
|
+
delimiter,
|
94
|
+
&block
|
95
|
+
)
|
96
|
+
end
|
93
97
|
end
|
94
98
|
when Array
|
95
|
-
obj.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
if obj.empty?
|
100
|
+
yield path, obj
|
101
|
+
else
|
102
|
+
obj.each_with_index do |ob, index|
|
103
|
+
path_nav(
|
104
|
+
ob,
|
105
|
+
(path ? [path, "[#{index}]"].join(delimiter) : "[#{index}]").to_s,
|
106
|
+
delimiter,
|
107
|
+
&block
|
108
|
+
)
|
109
|
+
end
|
102
110
|
end
|
103
111
|
else
|
104
112
|
yield path, obj
|
@@ -152,6 +160,6 @@ class Hash
|
|
152
160
|
# Each yield must produce an array with exactly two elements.
|
153
161
|
def hmap
|
154
162
|
return map unless block_given?
|
155
|
-
map { |k, v| yield(k, v) }.to_h
|
163
|
+
map { |k, v| yield(k, v) }.compact.to_h
|
156
164
|
end
|
157
165
|
end
|
data/lib/hash/hash_struct.rb
CHANGED
data/lib/hash/tree_hash.rb
CHANGED
data/lib/hash_path/hash_path.rb
CHANGED
@@ -48,11 +48,11 @@ module BBLib
|
|
48
48
|
def self.hash_path(hash, *paths, multi_path: false, multi_join: false, multi_join_hash: false)
|
49
49
|
tree = TreeHash.new(hash)
|
50
50
|
if multi_path
|
51
|
-
tree.find_multi(*paths).map { |r| r.map { |sr| sr
|
51
|
+
tree.find_multi(*paths).map { |r| r.map { |sr| sr.value } }
|
52
52
|
elsif multi_join
|
53
|
-
tree.find_join(*paths).map { |r| r.map { |sr| sr
|
53
|
+
tree.find_join(*paths).map { |r| r.map { |sr| sr.value } }
|
54
54
|
elsif multi_join_hash
|
55
|
-
tree.find_join(*paths).map { |r| r.map { |sr| sr
|
55
|
+
tree.find_join(*paths).map { |r| r.map { |sr| sr.value } }.to_h
|
56
56
|
else
|
57
57
|
tree.find(paths).map(&:value)
|
58
58
|
end
|