zhexdump 0.1.1 → 0.2.0

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
  SHA256:
3
- metadata.gz: c0405a9a00093fb08a5ff3294e1636d3350e49c83f478c2d4e1fa1575b72bb83
4
- data.tar.gz: 0cf51636f3344e94c0e9a5647fbe1cb9f54b1d134e0d22cd7c595d2f41a03552
3
+ metadata.gz: 87be9581b8556e6969275cb73e07ff353805db106f1f741bb522a941db276919
4
+ data.tar.gz: 0f75b82fe5bb212b0f4ad29d9aea29f89b62f21de3fabc7496c5eb75a387b1dc
5
5
  SHA512:
6
- metadata.gz: e117316024d5ecc48f7eefa79cff23603ef728959791c522a93aa50dafc50f05f202aeb17ee5994d2ebe9bd22c1d881840cfad3c6a392076c7aabd6da4f06b4d
7
- data.tar.gz: c3d12f02963fa811e42d44f93a328eebb2a81964350b2f3edebd7666f4ef2122c1fd01488e05be2d690784dae86fbdb0c2d109f76d9d9d929360a4ab3d911171
6
+ metadata.gz: 1fc327641290592b335173fc7385ef73344f0f5f45bad467f25e7edc5a20a130a0f5a4daf54888932c8084fe500823446ed69676c286fa1d48fc199310a92c5c
7
+ data.tar.gz: 0231db65834152f9a9afce551a689a4a786c6a77863acf981929054db6254e8e96f74df59e4aa5e3a8c8c18f5c289107f819abb0b84405e10cf096140fb9eba3
@@ -1,3 +1,3 @@
1
1
  module ZHexdump
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/zhexdump.rb CHANGED
@@ -19,7 +19,15 @@ module ZHexdump
19
19
  r
20
20
  end
21
21
 
22
+ @defaults = {}
23
+
22
24
  class << self
25
+ attr_accessor :defaults
26
+
27
+ def _get_param(h, key, default)
28
+ h[key] || defaults[key] || default
29
+ end
30
+
23
31
  def dump data, h = {}
24
32
  offset = h.fetch(:offset, 0)
25
33
  dedup = h.fetch(:dedup, true)
@@ -30,13 +38,13 @@ module ZHexdump
30
38
  offset = 0
31
39
  end
32
40
 
33
- add = h[:add] || 0
34
- size = h[:size] || (data.size-offset)
35
- tail = h[:tail] || "\n"
36
- width = h[:width] || 0x10 # row width, in bytes
37
- output = h[:output] || $>
38
- indent = h[:indent] || 0
39
- offset_format = h[:offset_format] || "%08x: "
41
+ add = _get_param(h, :add, 0)
42
+ size = _get_param(h, :size, data.size-offset)
43
+ tail = _get_param(h, :tail, "\n")
44
+ width = _get_param(h, :width, 16)
45
+ output = _get_param(h, :output, $stdout)
46
+ indent = _get_param(h, :indent, 0)
47
+ offset_format = _get_param(h, :offset_format, "%08x: ")
40
48
 
41
49
  indent = ' ' * indent
42
50
  size = data.size-offset if size+offset > data.size
@@ -47,8 +55,9 @@ module ZHexdump
47
55
  width.times do |i|
48
56
  hex << ' ' if i%8==0 && i>0
49
57
  if c = ((size > 0) && data[offset+i])
50
- hex << "%02x " % c.ord
51
- ascii << ((32..126).include?(c.ord) ? c : '.')
58
+ ord = c.ord
59
+ hex << "%02x " % ord
60
+ ascii << (ord == 0 ? ' ' : ((32..126).include?(ord) ? c : '.'))
52
61
  else
53
62
  hex << ' '
54
63
  ascii << ' '
data/spec/hexdump_spec.rb CHANGED
@@ -59,10 +59,10 @@ describe ZHexdump do
59
59
  s = ''
60
60
  ZHexdump.dump data, :output => s, :indent => 2
61
61
  a = s.split("\n")
62
- a[0].should == " 00000000: 66 6f 6f 62 61 72 00 00 00 00 00 00 00 00 00 00 |foobar..........|"
63
- a[1].should == " 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|"
62
+ a[0].should == " 00000000: 66 6f 6f 62 61 72 00 00 00 00 00 00 00 00 00 00 |foobar |"
63
+ a[1].should == " 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |"
64
64
  a[2].should == " *"
65
- a[3].should == " 00000060: 00 00 00 00 00 00 00 00 00 00 |.......... |"
65
+ a[3].should == " 00000060: 00 00 00 00 00 00 00 00 00 00 | |"
66
66
  end
67
67
 
68
68
  it "adds :add to offset shown" do
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require File.join(File.dirname(__FILE__), '../lib/zhexdump.rb')
2
2
 
3
3
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
4
4
  RSpec.configure do |config|
5
- config.treat_symbols_as_metadata_keys_with_true_values = true
6
5
  config.run_all_when_everything_filtered = true
7
6
  #config.filter_run :focus
8
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhexdump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-02 00:00:00.000000000 Z
11
+ date: 2024-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.5.6
64
+ rubygems_version: 3.5.16
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: A highly flexible hexdump implementation.