eac_ruby_utils 0.87.0 → 0.90.0

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: 1d4ecfbc2e97f7fb3f09539826cfeb26eca26eac7e12fd7ea396dbf1c26cdc88
4
- data.tar.gz: dfb7c05df973182295f4ad73c118e1825d80130e7a446a5a395ecd3d9c361e35
3
+ metadata.gz: 835bf57068df74ba63d257a3a724ea6c1bb55c61ce22d0641fbfb1d9ac1051ac
4
+ data.tar.gz: a968421702a2320f371123cafa19d4872276b3af2301272ce14162aedd02bb45
5
5
  SHA512:
6
- metadata.gz: 7dc1d1cf517eee4582a0359aa3868fea24b4305ee365dcf2c8509db75180c021a428256f8ea32d21ce88ce29a43a5a016ed0dcec39143d84ec9b359802dc6d83
7
- data.tar.gz: a7caf88e6692f6ff0ba15d0c231ca86bac511ef10eb539afaa3f4aac0556d50d19328822dac22ca8f5be69b4ef83cebfd06658ecaa9790f154ddc64ac6f0a1b9
6
+ metadata.gz: b6ad3ff00cc3d865bc6f580ac64961a4d034d1a1dea4634866846c12e925ec7f21136114afe479721a6cad6813b17f4b601e7acfadedefe43719de7e184e68ff
7
+ data.tar.gz: 2ae2e960541fc651edca20e53f2b2d772fc4fe45df09e4676a9275d007165f881b4674f0d37eda315e225f2b5d500b7fe6cf073ab3e6e63fd102202e7292586f
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/compare_by'
4
+
5
+ module EacRubyUtils
6
+ class Bit
7
+ VALID_VALUES = [0, 1].freeze
8
+
9
+ class << self
10
+ def assert(obj)
11
+ return obj if obj.is_a?(self)
12
+
13
+ new(obj.to_i)
14
+ end
15
+
16
+ def valid_integer?(value)
17
+ value.is_a?(::Integer) && VALID_VALUES.include?(value)
18
+ end
19
+
20
+ def validate_integer(value)
21
+ return value if valid_integer?(value)
22
+
23
+ raise(::ArgumentError, "Invalid bit value: #{value} (Valid: #{VALID_VALUES})")
24
+ end
25
+ end
26
+
27
+ attr_reader :value
28
+ compare_by :value
29
+ delegate :to_s, :zero?, to: :value
30
+
31
+ # @param value [Integer]
32
+ def initialize(value)
33
+ @value = self.class.validate_integer(value)
34
+ end
35
+
36
+ # @return [Boolean]
37
+ def one?
38
+ !zero?
39
+ end
40
+
41
+ # @return [Integer]
42
+ def to_i
43
+ value
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/bit'
4
+ require 'eac_ruby_utils/byte'
5
+ require 'eac_ruby_utils/byte_array'
6
+ require 'eac_ruby_utils/patches/module/compare_by'
7
+
8
+ module EacRubyUtils
9
+ class BitArray
10
+ class << self
11
+ def assert(obj)
12
+ return obj if obj.is_a?(self)
13
+ return new(obj) if obj.is_a?(::Enumerable)
14
+
15
+ raise "Could not convert #{obj} to #{self}"
16
+ end
17
+ end
18
+
19
+ delegate :each, :each_with_index, :to_a, :size, :count, :length, :[], :fetch, to: :values_array
20
+ compare_by :values_array
21
+
22
+ def initialize(values = [])
23
+ values.each { |value| push(value) }
24
+ end
25
+
26
+ def <<(value)
27
+ push(value)
28
+ end
29
+
30
+ # @param value [EacRubyUtils::Bit]
31
+ # @return [EacRubyUtils::Bit]
32
+ def push(value)
33
+ values_array.push(::EacRubyUtils::Bit.assert(value))
34
+ end
35
+
36
+ # @return [EacRubyUtils::BitArray]
37
+ def reverse
38
+ self.class.new(values_array.reverse)
39
+ end
40
+
41
+ # @param big_endian [Boolean]
42
+ # @return [EacRubyUtils::ByteArray]
43
+ def to_byte_array(big_endian = false)
44
+ unless count.modulo(::EacRubyUtils::Byte::BIT_COUNT).zero?
45
+ raise 'Bits returned is not multile of 8'
46
+ end
47
+
48
+ byte_bits_enumerator.each_with_object(::EacRubyUtils::ByteArray.new) do |e, a|
49
+ a << ::EacRubyUtils::Byte.from_bit_array(e, big_endian)
50
+ end
51
+ end
52
+
53
+ # @return [Array<Integer>]
54
+ def to_int_array
55
+ values_array.map(&:to_i)
56
+ end
57
+
58
+ private
59
+
60
+ def byte_bits_enumerator
61
+ ::Enumerator.new do |y|
62
+ offset = 0
63
+ while offset < values_array.count
64
+ y.yield(values_array.slice(offset, ::EacRubyUtils::Byte::BIT_COUNT))
65
+ offset += ::EacRubyUtils::Byte::BIT_COUNT
66
+ end
67
+ end
68
+ end
69
+
70
+ def values_array
71
+ @values_array ||= []
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/bit'
4
+ require 'eac_ruby_utils/bit_array'
5
+ require 'eac_ruby_utils/patches/module/compare_by'
6
+
7
+ module EacRubyUtils
8
+ class Byte
9
+ BIT_COUNT = 8
10
+ BIT_INDEX_RANGE = (0..7).freeze
11
+ VALUE_RANGE = (0..255).freeze
12
+
13
+ class << self
14
+ def assert(obj)
15
+ return obj if obj.is_a?(self)
16
+
17
+ new(obj.to_i)
18
+ end
19
+
20
+ def from_bit_array(bit_array, big_endian = false)
21
+ bit_array = ::EacRubyUtils::BitArray.assert(bit_array)
22
+ raise ::ArgumentError, "Wrong bit array size: #{bit_array.size}" if
23
+ bit_array.size != BIT_COUNT
24
+
25
+ bit_array = bit_array.reverse if big_endian
26
+ bit_array.each_with_index.inject(new(0)) do |a, e|
27
+ a.bit_set(e[1], e[0])
28
+ end
29
+ end
30
+
31
+ def valid_bit_index?(value)
32
+ value.is_a?(::Integer) && BIT_INDEX_RANGE.include?(value)
33
+ end
34
+
35
+ def validate_bit_index(value)
36
+ return value if valid_bit_index?(value)
37
+
38
+ raise(::ArgumentError, "Invalid bit index: #{value} (Range: #{BIT_INDEX_RANGE})")
39
+ end
40
+
41
+ def valid_value?(value)
42
+ value.is_a?(::Integer) && VALUE_RANGE.include?(value)
43
+ end
44
+
45
+ def validate_value(value)
46
+ return value if valid_value?(value)
47
+
48
+ raise(::ArgumentError, "Invalid byte value: #{value} (Range: #{VALUE_RANGE})")
49
+ end
50
+ end
51
+
52
+ attr_reader :value
53
+ compare_by :value
54
+
55
+ def initialize(value)
56
+ self.value = value
57
+ end
58
+
59
+ # @param bit_index [Integer]
60
+ # @return [EacRubyUtils::Bit]
61
+ def [](bit_index)
62
+ bit_get(bit_index)
63
+ end
64
+
65
+ # @param bit_index [Integer]
66
+ # @return [EacRubyUtils::Bit]
67
+ def bit_get(bit_index)
68
+ self.class.validate_bit_index(bit_index)
69
+
70
+ ::EacRubyUtils::Bit.new((value & (1 << bit_index)) >> bit_index)
71
+ end
72
+
73
+ def bit_set(bit_index, bit_value)
74
+ self.class.validate_bit_index(bit_index)
75
+ bit = ::EacRubyUtils::Bit.assert(bit_value)
76
+ mask = (1 << bit_index)
77
+ self.class.new(bit.zero? ? value & ~mask : value | mask)
78
+ end
79
+
80
+ def to_bit_array
81
+ BIT_INDEX_RANGE.map { |bit_index| self[bit_index] }
82
+ end
83
+
84
+ # @return [Integer]
85
+ def to_i
86
+ value
87
+ end
88
+
89
+ private
90
+
91
+ attr_writer :value
92
+ end
93
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/byte'
4
+ require 'eac_ruby_utils/patches/module/compare_by'
5
+
6
+ module EacRubyUtils
7
+ class ByteArray
8
+ delegate :to_a, :size, :count, :length, :[], :fetch, to: :values_array
9
+ compare_by :values_array
10
+
11
+ def initialize(values = [])
12
+ values.each { |value| push(value) }
13
+ end
14
+
15
+ def <<(value)
16
+ push(value)
17
+ end
18
+
19
+ # @param value [EacRubyUtils::Byte]
20
+ # @return [EacRubyUtils::Byte]
21
+ def push(value)
22
+ values_array.push(::EacRubyUtils::Byte.assert(value))
23
+ end
24
+
25
+ # @return [Array<Integer>]
26
+ def to_int_array
27
+ values_array.map(&:to_i)
28
+ end
29
+
30
+ private
31
+
32
+ def values_array
33
+ @values_array ||= []
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/fs/extname'
4
+ require 'pathname'
5
+
6
+ class Pathname
7
+ def basename_noext(limit = 1)
8
+ basename(::EacRubyUtils::Fs.extname(basename.to_path, limit))
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ class Pathname
6
+ # A .glob that raises a ::RuntimeError if +self+ is not a directory.
7
+ # @return [Pathname]
8
+ def reqdir_glob(*args)
9
+ raise ::RuntimeError, "\"#{self}\" is not a directory" unless directory?
10
+
11
+ glob(*args)
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.87.0'
4
+ VERSION = '0.90.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.87.0
4
+ version: 0.90.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-06 00:00:00.000000000 Z
11
+ date: 2022-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,9 +102,13 @@ files:
102
102
  - lib/eac_ruby_utils.rb
103
103
  - lib/eac_ruby_utils/abstract_methods.rb
104
104
  - lib/eac_ruby_utils/arguments_consumer.rb
105
+ - lib/eac_ruby_utils/bit.rb
106
+ - lib/eac_ruby_utils/bit_array.rb
105
107
  - lib/eac_ruby_utils/blank_not_blank.rb
106
108
  - lib/eac_ruby_utils/boolean.rb
107
109
  - lib/eac_ruby_utils/by_reference.rb
110
+ - lib/eac_ruby_utils/byte.rb
111
+ - lib/eac_ruby_utils/byte_array.rb
108
112
  - lib/eac_ruby_utils/common_concern.rb
109
113
  - lib/eac_ruby_utils/common_concern/class_setup.rb
110
114
  - lib/eac_ruby_utils/common_concern/module_setup.rb
@@ -205,11 +209,13 @@ files:
205
209
  - lib/eac_ruby_utils/patches/object/to_pathname.rb
206
210
  - lib/eac_ruby_utils/patches/object/to_uri.rb
207
211
  - lib/eac_ruby_utils/patches/pathname.rb
212
+ - lib/eac_ruby_utils/patches/pathname/basename_noext.rb
208
213
  - lib/eac_ruby_utils/patches/pathname/basename_sub.rb
209
214
  - lib/eac_ruby_utils/patches/pathname/if_exist.rb
210
215
  - lib/eac_ruby_utils/patches/pathname/mkpath_s.rb
211
216
  - lib/eac_ruby_utils/patches/pathname/parent_n.rb
212
217
  - lib/eac_ruby_utils/patches/pathname/readlink_r.rb
218
+ - lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb
213
219
  - lib/eac_ruby_utils/patches/regexp.rb
214
220
  - lib/eac_ruby_utils/patches/regexp/if_match.rb
215
221
  - lib/eac_ruby_utils/patches/regexp/to_parser.rb