hex_extensions 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/hex_extensions.gemspec +23 -0
- data/lib/hex_extensions/version.rb +3 -0
- data/lib/hex_extensions.rb +77 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d4470086f179fffb890afafb854206b69d2d9b8
|
4
|
+
data.tar.gz: 883b60499ca9efefa6f4caadc747f2151e10e256
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f93369c54d4d70f5b9dfa20e60612e9c765ad72b5840563018a249db67f7a007ad5184005e1390efbf18bacb6cb49bebb219f96b9ece067e4f10edc04604b7bc
|
7
|
+
data.tar.gz: 2647cec018e3ffd1dc8381e02344e1725b393b4ae680f5735640c2b34984d995a0fabda6b90673052d623ca34adeff53443fdf4e2174f4585dca929819078e6a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 coco
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# HexExtensions
|
2
|
+
|
3
|
+
Usefull extensions to common classes
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'hex_extensions'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install hex_extensions
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/hexgolems/hex_extensions/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hex_extensions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hex_extensions"
|
8
|
+
spec.version = HexExtensions::VERSION
|
9
|
+
spec.authors = ["coco"]
|
10
|
+
spec.email = ["coco@hexgolems.com"]
|
11
|
+
spec.summary = %q{Common usefull methods, no monkey patches}
|
12
|
+
spec.description = %q{Usefull methods for Ranges, Hashes. Currently no monkeypatches are performed.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "hex_extensions/version"
|
2
|
+
|
3
|
+
module Hex
|
4
|
+
|
5
|
+
KILOBYTE = 1024
|
6
|
+
MEGABYTE = 1024 * KILOBYTE
|
7
|
+
GIGABYTE = 1024 * MEGABYTE
|
8
|
+
|
9
|
+
def assert(desc = nil, &block)
|
10
|
+
fail "assertion failed #{desc}\n #{Kernel.caller}" unless block.call
|
11
|
+
end
|
12
|
+
module_function :assert
|
13
|
+
|
14
|
+
def deep_copy(o)
|
15
|
+
Marshal.load(Marshal.dump(o))
|
16
|
+
end
|
17
|
+
module_function :deep_copy
|
18
|
+
|
19
|
+
def parse_range(str)
|
20
|
+
return case str
|
21
|
+
when/\A(\d+)\.\.(\d+)\Z/ then ($1.to_i..$2.to_i)
|
22
|
+
when/\A(\d+)\.\.\.(\d+)\Z/ then ($1.to_i...$2.to_i)
|
23
|
+
else raise "invalid range #{range_str}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
module_function :parse_range
|
27
|
+
|
28
|
+
def range_intersection(rangea,rangeb)
|
29
|
+
assert { rangeb.class == Range }
|
30
|
+
assert { rangea.class == Range }
|
31
|
+
assert { rangeb.min }
|
32
|
+
assert { rangea.min }
|
33
|
+
res = ( [rangea.min, rangeb.min].max .. [rangea.max, rangeb.max].min )
|
34
|
+
return nil if res.first > res.last
|
35
|
+
res
|
36
|
+
end
|
37
|
+
module_function :range_intersection
|
38
|
+
|
39
|
+
def range_contains?(bigger,smaller)
|
40
|
+
bigger.min <= smaller.min && bigger.max >= smaller.max
|
41
|
+
end
|
42
|
+
module_function :range_contains?
|
43
|
+
|
44
|
+
def range_hex_inspect(range)
|
45
|
+
"(#{range.min.to_s(16)}..#{range.max.to_s(16)})"
|
46
|
+
end
|
47
|
+
module_function :range_hex_inspect
|
48
|
+
|
49
|
+
def hash_map_keys(hash, &block)
|
50
|
+
hash.each_pair.reduce({}) { |h, (key, val)| new_key = block.call(key, val); h[new_key] = val; h }
|
51
|
+
end
|
52
|
+
module_function :hash_map_keys
|
53
|
+
|
54
|
+
def hash_map_values(hash, &block)
|
55
|
+
hash.each_pair.reduce({}) { |h, (key, val)| h[key] = block.call(key, val); h }
|
56
|
+
end
|
57
|
+
module_function :hash_map_values
|
58
|
+
|
59
|
+
def hash_map_pairs(hash, &block)
|
60
|
+
hash.each_pair.reduce({}) { |h, (key, val)| new_key, new_val = block.call(key, val); h[new_key] = new_val; h }
|
61
|
+
end
|
62
|
+
module_function :hash_map_pairs
|
63
|
+
|
64
|
+
def hash_flatten(hash)
|
65
|
+
res = {}
|
66
|
+
each_pair do |key, val|
|
67
|
+
if val.is_a? Hash
|
68
|
+
res.merge! hash_flatten_hash
|
69
|
+
else
|
70
|
+
res[key] = val
|
71
|
+
end
|
72
|
+
end
|
73
|
+
res
|
74
|
+
end
|
75
|
+
module_function :hash_flatten
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hex_extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- coco
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-04 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
description: Usefull methods for Ranges, Hashes. Currently no monkeypatches are performed.
|
42
|
+
email:
|
43
|
+
- coco@hexgolems.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- hex_extensions.gemspec
|
54
|
+
- lib/hex_extensions.rb
|
55
|
+
- lib/hex_extensions/version.rb
|
56
|
+
homepage: ''
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Common usefull methods, no monkey patches
|
80
|
+
test_files: []
|