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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f30c8697a0a889c6584b6dde7034f7dd9cbcd51f
4
- data.tar.gz: 0592fc41e13230948a121b693d37bd854f8218aa
3
+ metadata.gz: 43dd3d37f8a059ac06a6d5dcf9cef50fe132276c
4
+ data.tar.gz: 001bf8c19902d02b13efa4d3f925b4b0c7a1a893
5
5
  SHA512:
6
- metadata.gz: e2e7491db5fdf5fc7b43a7e0aa451fdf52d41811fa78086662db88868b4d7658784385af493da2ecf845b131b7976ff949f323748d8f25e09146a8fc0f8947e9
7
- data.tar.gz: f32fbdc7b6d23f10669839f62eebb74a26d403e64756d3f8d2fd86af017fad2207eb070b3119969417dd24547440a46d1c49f093a8142ee58deef85017bbd39f
6
+ metadata.gz: 0d68b37009779644326f1355e21be21267e6e7171e457943abf419fe2dc7a3d83b47e2ba134488d85047f65d35a8e22ecbeb139714869454507106200409ca77
7
+ data.tar.gz: 2809a8c9109c2d5bb847cc4895bae992012581930eb1ee9a10150bd6cec43070394e2ea3c654aa8cc641c014447ab4bb26bd9e25a824b2771f664b6f26597af4
@@ -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[:style]) }
6
+ return _x.collect{ |e| stylify(e, slicer, opts) }
7
7
  else
8
- return stylify(_x, slicer, opts[:style])
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, _style
16
- return (_style == :data ? '' : '[') \
17
- + to_hex_string(_x, _slicer) \
18
- + (_style == :data ? '' : ']')
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
- format = '%' \
23
- + (_slicer == :data ? (@@config.pad_zeros ? '0' : '') : '0') \
24
- + (@@config.word_size / 4).to_s \
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 @@config.word_size / 2 / 4
31
- else @@config.word_size / 4
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('')
@@ -1,3 +1,3 @@
1
1
  module CuteHex
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-22 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport