cute-hex 0.0.1 → 0.0.2
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 +4 -4
- data/lib/cute-hex/core.rb +16 -13
- data/lib/cute-hex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 43dd3d37f8a059ac06a6d5dcf9cef50fe132276c
|
|
4
|
+
data.tar.gz: 001bf8c19902d02b13efa4d3f925b4b0c7a1a893
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d68b37009779644326f1355e21be21267e6e7171e457943abf419fe2dc7a3d83b47e2ba134488d85047f65d35a8e22ecbeb139714869454507106200409ca77
|
|
7
|
+
data.tar.gz: 2809a8c9109c2d5bb847cc4895bae992012581930eb1ee9a10150bd6cec43070394e2ea3c654aa8cc641c014447ab4bb26bd9e25a824b2771f664b6f26597af4
|
data/lib/cute-hex/core.rb
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
module CuteHex
|
|
2
2
|
def self.hex_print _x, **opts
|
|
3
|
-
slicer = opts[:style] == :data ? @@config.slicer : :nibble
|
|
3
|
+
slicer = opts[:style] == :data ? (opts[:slicer] || @@config.slicer) : :nibble
|
|
4
4
|
|
|
5
5
|
if _x.is_a? Array
|
|
6
|
-
return _x.collect{ |e| stylify(e, slicer, opts
|
|
6
|
+
return _x.collect{ |e| stylify(e, slicer, opts) }
|
|
7
7
|
else
|
|
8
|
-
return stylify(_x, slicer, opts
|
|
8
|
+
return stylify(_x, slicer, opts)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
singleton_class.send(:alias_method, :x, :hex_print)
|
|
13
13
|
|
|
14
14
|
private
|
|
15
|
-
def self.stylify _x, _slicer,
|
|
16
|
-
return (
|
|
17
|
-
+ to_hex_string(_x, _slicer)
|
|
18
|
-
+ (
|
|
15
|
+
def self.stylify _x, _slicer, _opts
|
|
16
|
+
return (_opts[:style] == :data ? '' : '[') \
|
|
17
|
+
+ to_hex_string(_x, _slicer, _opts) \
|
|
18
|
+
+ (_opts[:style] == :data ? '' : ']')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def self.to_hex_string _x, _slicer
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
def self.to_hex_string _x, _slicer, _opts
|
|
22
|
+
word_size = _opts[:word_size] || @@config.word_size
|
|
23
|
+
pad_zeros = _opts[:pad_zeros] == nil ? @@config.pad_zeros : _opts[:pad_zeros]
|
|
24
|
+
|
|
25
|
+
format = '%' \
|
|
26
|
+
+ (_opts[:style] == :data ? (pad_zeros ? '0' : '') : '0') \
|
|
27
|
+
+ (word_size / 4).to_s \
|
|
25
28
|
+ 'X'
|
|
26
29
|
|
|
27
30
|
slice_by = case _slicer
|
|
28
31
|
when :byte then 2
|
|
29
32
|
when :nibble then 4
|
|
30
|
-
when :half_word then
|
|
31
|
-
else
|
|
33
|
+
when :half_word then word_size / 2 / 4
|
|
34
|
+
else word_size / 4
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
s = sprintf(format, _x).split('')
|
data/lib/cute-hex/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cute-hex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gloria Budiman
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-02-
|
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|