hexutils 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +82 -1
  3. data/Rakefile +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58d93d37042b54496a85566264d827f2852ed034ecf6356b63ec121561230347
4
- data.tar.gz: 999e485f063f2e1753f9541e94bd34deb2a0c609bb26b03e551be0b234ffe7c9
3
+ metadata.gz: 6395e84bd47bbfc360828297a903fe7a2ed2bd21b24cef24eae317b9dac1e7af
4
+ data.tar.gz: f7437d610cb255cb9d060abd9545ed52fd0942dd85a541e55764d5ae5b8f5afe
5
5
  SHA512:
6
- metadata.gz: 04aeca2de8a683f4d3a5080e23cb10ceb3d38aa580bbaa127b267315e59fe38bd4da3de416cdf6081d233395d35772091b6389e1fe5f1d2750c84849e80145dc
7
- data.tar.gz: 5f978fc664a4398e8148c96812875910a6db8629e1448acec559efe76c368efa79f8d4c30c3accb55fb480069a270cab00eb6eac6ac2ad34111a685f94590583
6
+ metadata.gz: 8c3b815f9ed70e5d7da60a9ae3d8cc373feac6dcecd70195545969a09766fae81ad5335cb70c0111df20176e5247ca7e4412306074268bd53201cb770612661e
7
+ data.tar.gz: ae3c26841ac1acebef0afe9d5dd64158f2772687f520b9450c88fbd7f8d88f5354d3a991c0453c1161028d1f67cfc58515e774448263651f58d0d49df868c028
data/README.md CHANGED
@@ -10,11 +10,92 @@ hexutils - hex(adecimal) encode/decode helpers 'n' more for String, NilClass, Ke
10
10
 
11
11
 
12
12
 
13
+ Part of the [**If I Were ~~King~~ Matz (aka Yukihiro Matsumoto) - Ideas For Ruby 4.0 - What's Broken & Missing in Ruby 3.x and How To Fix It**](https://github.com/rubycocos/core#if-i-were-king-matz-aka-yukihiro-matsumoto---ideas-for-ruby-40-----whats-broken--missing-in-ruby-3x-and-how-to-fix-it)
14
+ Series
15
+
13
16
 
14
17
 
15
18
  ## Usage
16
19
 
17
- To be done
20
+
21
+ For some background on working with bin(ary) and hex(adecimal)
22
+ strings in ruby
23
+ see the [**Programming Bits, Bytes 'n' Blocks Step-by-Step Book / Guide**](https://github.com/rubycocos/core/tree/master/bytes#background----programming-bits-bytes-n-blocks-step-by-step-book--guide)
24
+ Let's start with the three types of strings, that is, bytes, string buffers, and frozen strings, ...
25
+
26
+
27
+
28
+ To make programming hex(adecimal) strings easier
29
+ let's add some encode / decode helpers.
30
+
31
+
32
+ ### Kernel - `decode_hex` (or `hex`) and `encode_hex`
33
+
34
+ ``` ruby
35
+ require 'hexutils'
36
+
37
+ # get a bin(ary) string from a hex(adecimal) string
38
+ hex '0xffff' # or
39
+ hex( '0xffff' ) # or
40
+ decode_hex( '0xffff' )
41
+ #=> "\xff\xff".b
42
+
43
+ # get a hex(a)decimal string from a bin(ary) string
44
+ encode_hex( "\xff\xff".b )
45
+ #=> "ffff"
46
+ ```
47
+
48
+ Note: The decode_hex `decode_hex` (or `hex`)
49
+ allows all variants of upper- and lowercase
50
+ with or without the `0x`/`0X` prefix
51
+ e.g. '0XFFFF', 'FFFF', 'ffff', etc.
52
+ For convenience whitespace incl.
53
+ newlines are allowed anywhere.
54
+
55
+
56
+
57
+ ### String - `to_hex` (or `hex`) and `hex?` (or `is_hex?`)
58
+
59
+ ``` ruby
60
+ # get a hex(a)decimal string from a bin(ary) string
61
+ "\xff\xff".b.hex # or
62
+ "\xff\xff".b.to_hex # or
63
+ #=> "ffff"
64
+
65
+ "\xff\xff".b.hex? # or
66
+ "\xff\xff".b.is_hex?
67
+ #=> false
68
+
69
+ "ffff".hex? # or
70
+ "ffff".is_hex? # or
71
+ "0xffff".is_hex? # or
72
+ "0XFFFF".is_hex? # or
73
+ #=> true
74
+ ```
75
+
76
+
77
+ NOTE: The "old" `String#hex` method that returns a integer number
78
+ from a hex(adecimal) string gets "monkey patched" or is that rewired?
79
+ to `String#old_hex` and `String#hexnum`.
80
+
81
+
82
+
83
+ ### Bonus: NilClass - to_hex (or hex) and hex? (or is_hex?)
84
+
85
+ ``` ruby
86
+ nil.hex? # or
87
+ nil.is_hex?
88
+ #=> false
89
+
90
+ nil.hex # or
91
+ nil.to_hex
92
+ #=> ''
93
+ ```
94
+
95
+
96
+
97
+ That's it for now.
98
+
18
99
 
19
100
 
20
101
  ## License
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'hoe'
3
3
 
4
4
  Hoe.spec 'hexutils' do
5
5
 
6
- self.version = '0.0.1'
6
+ self.version = '1.0.0'
7
7
 
8
8
  self.summary = "hexutils - hex(adecimal) encode/decode helpers 'n' more for String, NilClass, Kernel and more"
9
9
  self.description = summary
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer