bytes 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +62 -2
  3. data/Rakefile +1 -1
  4. data/lib/bytes/version.rb +2 -2
  5. data/lib/bytes.rb +15 -11
  6. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a8baa99382e45238e96527a5aab45a04daf4b73a2d4e1f64b3bf87530e14a7d
4
- data.tar.gz: ec170b28a4efd3d7b0cdf45094831a68a86d60785f313668baa24cbf5a106085
3
+ metadata.gz: 4d93d96204652bc075816b6b9a32220b7f1f72fa3765379012ecea3dfc4485c3
4
+ data.tar.gz: ba15bcb1f6939fd5ddb4d42da815a9ecb7edfc42e785c81bc8845101dc819b9a
5
5
  SHA512:
6
- metadata.gz: 8f62ad42592bfd8e69fb9bf53526ba19e3568b7140f88bfa9bf524ee1ac8af3258dd2d156f6080d08e63ecbcb92cf0e8f531f56f4c3b32faad8477b7efdf8423
7
- data.tar.gz: 728487df6ca9ad9cbe4aedcc2ae76c3f7018c195a780a5e4ef7ee487602cf0ac7fadff8b5c31b38a6e18f6a324947a1ae7e51f3c693bb65ae000ce6461a54969
6
+ metadata.gz: d3f41e967326e54022df7c16257fab59dc8bfe3d0402ba74670b16532d086162b74156937e3b4f40f2a09aee5a73521e1399b0329232da418a18599a48cfcfe1
7
+ data.tar.gz: 71726839412c32893a6f1a243cf4d00d84ba1558379f39e2e355940b645a5970a72c07a249481f11046486853926d8afd44aa28b4ef7ebc90afc9674534eaeb0
data/README.md CHANGED
@@ -246,12 +246,72 @@ To be continued ...
246
246
 
247
247
 
248
248
 
249
+ ## Usage
249
250
 
251
+ ### BytesHelper - From Bytes (Binary String) to Hex(adecimal) String and Back
252
+
253
+ ``` ruby
254
+ require 'bytes
255
+
256
+ Bytes.bin_to_hex( "\x61\x62".b )
257
+ #=> '6162'
258
+
259
+ Bytes.hex_to_bin( '6162' ) # or
260
+ Bytes.hex_to_bin( '0x6162' ) # or
261
+ #=> "\x61\x62".b
262
+
263
+ Bytes.is_hex?( '6162' )
264
+ Bytes.is_hex?( '0x6162' )
265
+ Bytes.is_hex?( '' ) # empty string or
266
+ Bytes.is_hex?( '0x' ) # empty hex string
267
+ #=> true
268
+
269
+ Bytes.is_hex?( 'xyz' )
270
+ Bytes.is_hex?( '0xyz' )
271
+ #=> false
272
+
273
+ Bytes.hex_to_bin( 'xzy' ) # or
274
+ Bytes.hex_to_bin( '0xxzy' )
275
+ #=> raises TypeError - non-hexadecimal digit found
276
+ ```
277
+
278
+ Note: You can use the shorter alternate alias
279
+ names `btoh` or `htob`
280
+ for `bin_to_hex` and `hex_to_bin`.
281
+
282
+
283
+ Or use the mixed-in String class variants. Example:
284
+
285
+ ``` ruby
286
+ "\x61\x62".b.bin_to_hex # or
287
+ "\x61\x62".b.btoh
288
+ #=> '6162'
289
+
290
+ '6162'.hex_to_bin # or
291
+ '6162'.htob # or
292
+ '0x6162'.hex_to_bin # or
293
+ '0x6162'.htob # or
294
+ #=> "\x61\x62".b
295
+
296
+ '6162'.is_hex?
297
+ '0x6162'is_hex?
298
+ ''.is_hex? # empty string or
299
+ '0x'.is_hex? # empty hex string
300
+ #=> true
301
+
302
+ 'xyz'is_hex?
303
+ '0xyz'.is_hex?
304
+ #=> false
305
+
306
+ 'xzy'.htob # or
307
+ '0xxzy'.htob
308
+ #=> raises TypeError - non-hexadecimal digit found
309
+ ```
310
+
311
+ and so on.
250
312
 
251
313
 
252
- ## Usage
253
314
 
254
- To be done
255
315
 
256
316
 
257
317
  ## License
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ Hoe.spec 'bytes' do
6
6
 
7
7
  self.version = Cocos::Module::Bytes::VERSION
8
8
 
9
- self.summary = "bytes"
9
+ self.summary = "bytes - bits 'n' bytes made easy/easier incl. new buffer helper / wrapper class to help with the string byte vs character dichotomy"
10
10
  self.description = summary
11
11
 
12
12
 
data/lib/bytes/version.rb CHANGED
@@ -3,8 +3,8 @@ module Cocos
3
3
  module Module
4
4
  module Bytes
5
5
 
6
- MAJOR = 0
7
- MINOR = 2
6
+ MAJOR = 1
7
+ MINOR = 0
8
8
  PATCH = 0
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
data/lib/bytes.rb CHANGED
@@ -6,6 +6,7 @@ require 'forwardable'
6
6
  require_relative 'bytes/version' # note: let version always go first
7
7
 
8
8
 
9
+
9
10
  module BytesHelper
10
11
  def hex_to_bin( hex )
11
12
  ## todo/fix: do an argument regex hex check!!!!
@@ -18,8 +19,8 @@ module BytesHelper
18
19
  [hex].pack('H*')
19
20
  end
20
21
  end
21
- alias_method :hex_to_bytes, :hex_to_bin
22
- alias_method :h_to_b, :hex_to_bin
22
+ ## alias_method :hex_to_bytes, :hex_to_bin
23
+ ## alias_method :h_to_b, :hex_to_bin
23
24
  alias_method :htob, :hex_to_bin
24
25
 
25
26
 
@@ -32,8 +33,8 @@ module BytesHelper
32
33
  hex.encode!( Encoding::UTF_8 )
33
34
  hex
34
35
  end
35
- alias_method :bytes_to_hex, :bin_to_hex
36
- alias_method :b_to_h, :bin_to_hex
36
+ ## alias_method :bytes_to_hex, :bin_to_hex
37
+ ## alias_method :b_to_h, :bin_to_hex
37
38
  alias_method :btoh, :bin_to_hex
38
39
 
39
40
 
@@ -81,8 +82,8 @@ class Bytes
81
82
  :size, :length
82
83
 
83
84
 
84
- def to_s() Bytes.bin_to_hex( @bin ); end
85
- alias_method :to_hex, :to_s
85
+ def to_hex() Bytes.bin_to_hex( @bin ); end
86
+ alias_method :to_s, :to_hex
86
87
 
87
88
  def b() @bin; end
88
89
 
@@ -119,12 +120,15 @@ end
119
120
 
120
121
 
121
122
  class String
122
- def to_hex() Bytes.bin_to_hex( self ); end
123
- ## add more aliases e.g. bin_to_hex or btoh or b_to_h or such - why? why not?
124
-
123
+ def bin_to_hex() Bytes.bin_to_hex( self ); end
124
+ alias_method :btoh, :bin_to_hex
125
+ alias_method :to_hex, :bin_to_hex
125
126
  ## note: built-in String#hex returns string converted
126
- ## to Integer -same as String.to_i(16) !!!!
127
- end
127
+ ## to Integer - same as String.to_i(16) !!!!
128
+
129
+ def hex_to_bin() Bytes.hex_to_bin( self ); end
130
+ alias_method :htob, :hex_to_bin
131
+ end # class String
128
132
 
129
133
 
130
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bytes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-10 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -44,7 +44,8 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.23'
47
- description: bytes
47
+ description: bytes - bits 'n' bytes made easy/easier incl. new buffer helper / wrapper
48
+ class to help with the string byte vs character dichotomy
48
49
  email: wwwmake@googlegroups.com
49
50
  executables: []
50
51
  extensions: []
@@ -83,5 +84,6 @@ requirements: []
83
84
  rubygems_version: 3.3.7
84
85
  signing_key:
85
86
  specification_version: 4
86
- summary: bytes
87
+ summary: bytes - bits 'n' bytes made easy/easier incl. new buffer helper / wrapper
88
+ class to help with the string byte vs character dichotomy
87
89
  test_files: []