iostruct 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7f2b827b6b7e4a2b1cb996da1f9218cd2877d1fc68db4e15fbe22f04a78b368
4
- data.tar.gz: b9673591f5634d59199e0364ac28f075e18c9f42286b1bdd0ac5d5b3c7e5eeb4
3
+ metadata.gz: 535a978c6d95f5213d7a7e63523b46788adc2d6ca83c714758e9f30f927f546f
4
+ data.tar.gz: 5f52aea99a2615221a62e9b7d3228f129f1320e2a21c8b65eae3fec644e4007a
5
5
  SHA512:
6
- metadata.gz: e167d6a4a84f9b7aeac11fe2023c91fc09c322194e783b42201a5d9dffdc090734e8e8efb70fdbe946c88553ba6f9ef6700634f5b96314c9cf1b921d4502c527
7
- data.tar.gz: 16bedc238561494e96ef5e7d5c6b8db56cb8506a9dfebe8ac780243a1b9edd716bbb07e8ca361df37a9700960daba2cf3037c67573bfa3c225ec646085ac1521
6
+ metadata.gz: 5a7489c0f185fb36a4e54c51273c2b87bd344754522e6584b329f529ed0ae00c8c287a1abf224b4cd3bfc1ed44fa5694c8036c89b3ef881231f8cfb4f773b6b0
7
+ data.tar.gz: 4fa626885e4446c846594c1be13b67649928e45e919aabc660cc2c414c7cb225efb29841e5bd856737d905d988f5dd2219dd3c1622c976cb2e656799beb2a0fe
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IOStruct
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/iostruct.rb CHANGED
@@ -129,8 +129,18 @@ module IOStruct
129
129
  end # InstanceMethods
130
130
 
131
131
  module HexInspect
132
- def inspect
133
- @fmtstr ||= "<#{self.class.to_s} " + self.class.const_get('FIELDS').map do |name, f|
132
+ def to_s
133
+ s = "<#{self.class.to_s} " + to_h.map do |k, v|
134
+ if v.is_a?(Integer) && v > 9
135
+ "#{k}=0x%x" % v
136
+ else
137
+ "#{k}=#{v.inspect}"
138
+ end
139
+ end.join(' ') + ">"
140
+ end
141
+
142
+ def to_table
143
+ @fmtstr_tbl = "<#{self.class.to_s} " + self.class.const_get('FIELDS').map do |name, f|
134
144
  fmt =
135
145
  case
136
146
  when f.type == Integer
@@ -142,7 +152,11 @@ module IOStruct
142
152
  end
143
153
  "#{name}=#{fmt}"
144
154
  end.join(' ') + ">"
145
- sprintf @fmtstr, *to_a.map{ |v| v.is_a?(String) ? v.inspect : v }
155
+ sprintf @fmtstr_tbl, *to_a.map{ |v| v.is_a?(String) ? v.inspect : v }
156
+ end
157
+
158
+ def inspect
159
+ to_s
146
160
  end
147
161
  end
148
162
  end # IOStruct
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.5.6
92
+ rubygems_version: 3.5.3
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: A Struct that can read/write itself from/to IO-like objects