bit_hash 0.1.0 → 0.1.1
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.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/bit_hash.gemspec +4 -4
- data/lib/bit_hash.rb +16 -15
- data/spec/bit_hash_spec.rb +4 -0
- metadata +3 -3
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
|
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
|
-
gem "to_insane", ">=0.2.
|
5
|
+
gem "to_insane", ">=0.2.2"
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bit_hash.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bit_hash}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Ong"]
|
@@ -44,14 +44,14 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.specification_version = 3
|
45
45
|
|
46
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<to_insane>, [">= 0.2.
|
47
|
+
s.add_runtime_dependency(%q<to_insane>, [">= 0.2.2"])
|
48
48
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
49
49
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
50
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
51
51
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
52
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
53
53
|
else
|
54
|
-
s.add_dependency(%q<to_insane>, [">= 0.2.
|
54
|
+
s.add_dependency(%q<to_insane>, [">= 0.2.2"])
|
55
55
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
56
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
57
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -59,7 +59,7 @@ Gem::Specification.new do |s|
|
|
59
59
|
s.add_dependency(%q<rspec>, [">= 0"])
|
60
60
|
end
|
61
61
|
else
|
62
|
-
s.add_dependency(%q<to_insane>, [">= 0.2.
|
62
|
+
s.add_dependency(%q<to_insane>, [">= 0.2.2"])
|
63
63
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
64
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
65
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
data/lib/bit_hash.rb
CHANGED
@@ -7,7 +7,11 @@ class BitHash
|
|
7
7
|
# base is the base value you want to use. Defaults to a URL safe character base which is 63
|
8
8
|
# character set can also be changed but not really necessary. read to_insane doc for more details
|
9
9
|
def initialize(config_map=nil, *options)
|
10
|
-
|
10
|
+
@options = {
|
11
|
+
:base => :url_safe,
|
12
|
+
:char_set => nil,
|
13
|
+
}
|
14
|
+
@options = load_options(options)
|
11
15
|
@config = Hash.new
|
12
16
|
@default = Hash.new
|
13
17
|
#validate mapping
|
@@ -144,10 +148,8 @@ class BitHash
|
|
144
148
|
# takes a given config string and returns a mapped hash
|
145
149
|
# please read to_insane doc for info on base and char_set
|
146
150
|
def parse(config_string, *options)
|
147
|
-
load_options(options)
|
148
|
-
|
149
|
-
config_string[0..@options[:prefix].size] = nil unless @options[:prefix].nil?
|
150
|
-
config_string = config_string.from_insane(@options[:base],@options[:char_set]).to_s(2)
|
151
|
+
options = load_options(options)
|
152
|
+
config_string = config_string.from_insane(options[:base],options[:char_set]).to_s(2)
|
151
153
|
config_array = config_string.split('')
|
152
154
|
new_config = @default.dup
|
153
155
|
@config_map.each do |conf|
|
@@ -184,10 +186,9 @@ class BitHash
|
|
184
186
|
# turns hash into a small compact string.
|
185
187
|
# see to_insane rdoc for base, and char_set definitions
|
186
188
|
def to_s(*options)
|
187
|
-
load_options(options)
|
189
|
+
options = load_options(options)
|
188
190
|
str = ''
|
189
|
-
str <<
|
190
|
-
str << to_i.to_insane(@options[:base], @options[:char_set])
|
191
|
+
str << to_i.to_insane(options[:base], options[:char_set])
|
191
192
|
str
|
192
193
|
end
|
193
194
|
|
@@ -231,14 +232,14 @@ class BitHash
|
|
231
232
|
end
|
232
233
|
|
233
234
|
def load_options(options)
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
235
|
+
new_options = @options.dup
|
236
|
+
if options[0].kind_of? Hash
|
237
|
+
new_options.merge(options[0])
|
238
|
+
else
|
239
|
+
new_options[:base] = options[0] unless options[0].nil?
|
240
|
+
new_options[:char_set] = options[1] unless options[1].nil?
|
238
241
|
end
|
239
|
-
|
240
|
-
@options[:char_set] ||= nil
|
241
|
-
@options[:prefix] ||= nil
|
242
|
+
new_options
|
242
243
|
end
|
243
244
|
|
244
245
|
def get_check_config(key,conf)
|
data/spec/bit_hash_spec.rb
CHANGED
@@ -77,6 +77,10 @@ describe BitHash do
|
|
77
77
|
@config.parse(@config.to_s).should eql(@config.to_hash)
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should have load same config" do
|
81
|
+
@config.parse(@config.to_s(20),20).should eql(@config.to_hash)
|
82
|
+
end
|
83
|
+
|
80
84
|
it "should output equal it self after being converted and parsed" do
|
81
85
|
str = @config.to_s
|
82
86
|
bin = @config.to_bin
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bit_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Ong
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.2.
|
23
|
+
version: 0.2.2
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
hash:
|
118
|
+
hash: 898955667
|
119
119
|
segments:
|
120
120
|
- 0
|
121
121
|
version: "0"
|