zhexdump 0.0.1 → 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8b2e6bfef9bdafb2b9c55ca2682113a71e008e5e9fc5d2492e0a03f7fbb74abb
4
+ data.tar.gz: 6c8ffe4c3d33f5c1fbe2c79dd02263f5b57582abb7c12950d54def6e8e942ff3
5
+ SHA512:
6
+ metadata.gz: f6fe0c14cdf444797c7393def5d1949ad319fc93f86075efecc7f083e012d87e210f78530340cb4401919905445c2f7f79581b1fe45f7348c79a367629ae1090
7
+ data.tar.gz: 4c86d845b5820ac1ab2b51293e290cb3b8877005b80316355ae0e40b234d245f05560c80f3617791a14c47bdcd18e0b16a0c7314e5b811ba7104cb01a9730314
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ZHexdump
2
2
 
3
- A highly flexible hexdump implementation.
3
+ A very flexible hexdump implementation.
4
4
 
5
5
  ## Installation
6
6
 
@@ -39,6 +39,24 @@ Or install it yourself as:
39
39
  END
40
40
  ```
41
41
 
42
+ ### String#hexdump
43
+ ```ruby
44
+ "foobar".hexdump
45
+
46
+ # output:
47
+ 00000000: 66 6f 6f 62 61 72 |foobar |
48
+ ```
49
+
50
+ ### String#to_hexdump
51
+ ```ruby
52
+ s = 32.upto(63).map(&:chr).join
53
+ puts s.to_hexdump
54
+
55
+ # output:
56
+ 00000000: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
57
+ 00000010: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
58
+ ```
59
+
42
60
  ### Custom width
43
61
  ```ruby
44
62
  ZHexdump.dump "abc123"*2, :width => 3
data/README.md.tpl CHANGED
@@ -30,6 +30,17 @@ Or install it yourself as:
30
30
  puts "START\n#{s}END"
31
31
  ```
32
32
 
33
+ ### String#hexdump
34
+ ```ruby
35
+ "foobar".hexdump
36
+ ```
37
+
38
+ ### String#to_hexdump
39
+ ```ruby
40
+ s = 32.upto(63).map(&:chr).join
41
+ puts s.to_hexdump
42
+ ```
43
+
33
44
  ### Custom width
34
45
  ```ruby
35
46
  ZHexdump.dump "abc123"*2, :width => 3
@@ -1,3 +1,3 @@
1
1
  module ZHexdump
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/zhexdump.rb CHANGED
@@ -30,12 +30,15 @@ module ZHexdump
30
30
  offset = 0
31
31
  end
32
32
 
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] || $>
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: "
38
40
 
41
+ indent = ' ' * indent
39
42
  size = data.size-offset if size+offset > data.size
40
43
 
41
44
  prevhex = ''; c = nil; prevdup = false; start = offset
@@ -62,7 +65,7 @@ module ZHexdump
62
65
  end
63
66
  prevdup = true
64
67
  else
65
- row = (show_offset ? ("%08x: " % (offset + add)) : '') + hex
68
+ row = indent + (show_offset ? (offset_format % (offset + add)) : '') + hex
66
69
  yield(row, offset+add, ascii) if block_given?
67
70
  row << ' |' + ascii + "|"
68
71
  output << "\n" if offset > start
@@ -75,7 +78,7 @@ module ZHexdump
75
78
  break if size <= 0
76
79
  end
77
80
  if show_offset && prevdup
78
- row = "%08x: " % (offset + add)
81
+ row = indent + (offset_format % (offset + add))
79
82
  yield(row) if block_given?
80
83
  output << "\n" << row
81
84
  end
@@ -88,6 +91,10 @@ end # module ZHexdump
88
91
 
89
92
  Zhexdump = ZHexdump
90
93
 
94
+ class String
95
+ include ZHexdump
96
+ end
97
+
91
98
  if $0 == __FILE__
92
99
  h = {}
93
100
  case ARGV.size
data/spec/hexdump_spec.rb CHANGED
@@ -139,4 +139,23 @@ describe ZHexdump do
139
139
  end
140
140
  s.should == "00000000: 66 6f 6f |xxx |\n"
141
141
  end
142
+
143
+ it "String#hexdump dumps to stdout" do
144
+ data = "foo"
145
+ io = StringIO.new
146
+ begin
147
+ saved_stdout, $> = $>, io
148
+ data.hexdump
149
+ ensure
150
+ $> = saved_stdout
151
+ end
152
+
153
+ io.rewind
154
+ io.read.should == "00000000: 66 6f 6f |foo |\n"
155
+ end
156
+
157
+ it "String#to_hexdump dumps to a new string" do
158
+ data = "foo"
159
+ data.to_hexdump.should == "00000000: 66 6f 6f |foo |\n"
160
+ end
142
161
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhexdump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andrey "Zed" Zaikin
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-20 00:00:00.000000000 Z
11
+ date: 2024-04-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: A highly flexible hexdump implementation.
@@ -34,8 +31,8 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .rspec
34
+ - ".gitignore"
35
+ - ".rspec"
39
36
  - Gemfile
40
37
  - LICENSE.txt
41
38
  - README.md
@@ -48,27 +45,25 @@ files:
48
45
  - zhexdump.gemspec
49
46
  homepage: ''
50
47
  licenses: []
51
- post_install_message:
48
+ metadata: {}
49
+ post_install_message:
52
50
  rdoc_options: []
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
54
  requirements:
58
- - - ! '>='
55
+ - - ">="
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
59
  requirements:
64
- - - ! '>='
60
+ - - ">="
65
61
  - !ruby/object:Gem::Version
66
62
  version: '0'
67
63
  requirements: []
68
- rubyforge_project:
69
- rubygems_version: 1.8.24
70
- signing_key:
71
- specification_version: 3
64
+ rubygems_version: 3.5.6
65
+ signing_key:
66
+ specification_version: 4
72
67
  summary: A highly flexible hexdump implementation.
73
68
  test_files:
74
69
  - spec/hexdump_spec.rb