ruby-mext 0.13.1 → 0.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78ccba48470c02ded3d499f744ee4d7ab33f962770b040327a757bb5d02b0e58
4
- data.tar.gz: 0f54fea010fc53dbf156e6931823f308e27ad0d6d8b12355d4a70fb9a047fa7b
3
+ metadata.gz: 8827f153719404c7a58d76841b1035dec8554e0d1352b65a04437d67d53354a4
4
+ data.tar.gz: d3815f2309de12f1cc4b5b403709ec04c201a7500fcedc76484c048ad38f38da
5
5
  SHA512:
6
- metadata.gz: b425d4e16786d03eafa7b6f7b3d7a2e9f5f4f346e7b83c96514ece44ad81cfff91b9e42c267f0057e421953806e73575f3890d7eb98e0decba92e4e6ebe103ea
7
- data.tar.gz: 942bbcd0363ef7946620dd5303cc30e23ed463663c7900ef85cd3f306d670688fba2f3b47772fccad9734fc4a04c929a5d923cfd77c7e28eabfa126dd16edbf0
6
+ metadata.gz: 225682bc6a0c772a7aaa8f7136b9411a34aa39ab550158b6b78b8cc25afe7e4f00b3ad42b861c7eecb804b2360bae7cfb70acae3009933b73087ffa5a23fc9eb
7
+ data.tar.gz: e992d615c3ae63283e27d2b4187da1d8a2455c703121f89904e944b7158456c4817b529862c85025047fa04e2e54e6c5bfcd0e52ad504081dde6b39d68da150e
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "ruby/mext"
4
+ require "ruby-mext"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,91 @@
1
+ require 'byebug'
2
+
3
+ module Mext
4
+
5
+ #
6
+ # +Mext::EndlessArray+
7
+ #
8
+ # an +array+ with an internal index which will chug out the +next+
9
+ # or the previous value in an endless fashion (i.e. +mod'ding+
10
+ # the current index)
11
+ #
12
+ class EndlessArray < Array
13
+
14
+ attr_reader :cur, :restart_value
15
+
16
+ #
17
+ # +Mext::EndlessArray.new(me = [], rv = 0)+
18
+ #
19
+ # create an endless array with a regular array copy.
20
+ # Another optional argument is the +restart_value+
21
+ # (which defaults to 0)
22
+ #
23
+ def initialize(me = [], rv = 0)
24
+ self.replace(me)
25
+ @cur = @restart_value = rv
26
+ end
27
+
28
+ #
29
+ # +next(step = 1)+
30
+ #
31
+ # bumps the current index forward of a +step+ value and returns
32
+ # the current element of +array+
33
+ #
34
+ def next(step = 1)
35
+ res = self.current
36
+ @cur += step
37
+ @cur = [self.cur % self.size, self.restart_value].max
38
+ res
39
+ end
40
+
41
+ #
42
+ # +previous(step = 1)+
43
+ #
44
+ # bumps the index backwards and returns the
45
+ # previous element of the +array+
46
+ #
47
+ def previous(step = 1)
48
+ res = self.current
49
+ @cur -= step
50
+ cur_check = @cur - self.restart_value
51
+ @cur = cur_check < 0 ? (cur_check % self.size) : @cur
52
+ res
53
+ end
54
+
55
+ class RestartValueTooLarge < StandardError; end
56
+ #
57
+ # +restart_value=(v)+
58
+ #
59
+ # sets the +restart_value+ to +v+. Raises an exception if +v+ is larger
60
+ # than +self.size - 1+. When set, it changes the current index but only
61
+ # it is below the +restart_value+
62
+ #
63
+ def restart_value=(v)
64
+ raise RestartValueTooLarge if v >= self.size
65
+ @restart_value = v
66
+ @cur = [@cur, @restart_value].max
67
+ end
68
+
69
+ #
70
+ # +current+
71
+ #
72
+ # returns the value stored in the current location
73
+ #
74
+ def current
75
+ self[self.cur]
76
+ end
77
+
78
+ #
79
+ # +reset+
80
+ #
81
+ # reset the +current+ pointer to the +restart_value+
82
+ # and returns whatever happens to be in it.
83
+ #
84
+ def reset
85
+ @cur = self.restart_value
86
+ self.current
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,23 @@
1
+ class Array
2
+
3
+ class << self
4
+
5
+ #
6
+ # +fill_float(end_value, start_value = 0.0, step = 1.0)+
7
+ #
8
+ # fill a blank newly created array with +Float+ numbers which will range
9
+ # from +start_value+ to +end_value+ in steps of +step+
10
+ #
11
+ MINIMUM_STEP = 1e-32
12
+
13
+ def fill_float(end_value, start_value = 0.0, step = 1.0)
14
+ raise ArgumentError.new("step too small") unless step.abs > MINIMUM_STEP
15
+ res = new
16
+ ev = end_value - step
17
+ start_value.step(ev, step).each { |f| res << f }
18
+ res
19
+ end
20
+
21
+ end
22
+
23
+ end
data/lib/mext/array.rb CHANGED
@@ -9,4 +9,6 @@ end
9
9
  choose
10
10
  dotop
11
11
  scalarop
12
+ fill
13
+ endless_array
12
14
  ).each { |f| require File.join(Mext::ARRAY_PATH, f) }
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = '0.13.1'
2
+ VERSION = '0.14.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicola Bernardini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2019-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,8 @@ files:
117
117
  - lib/mext/array.rb
118
118
  - lib/mext/array/choose.rb
119
119
  - lib/mext/array/dotop.rb
120
+ - lib/mext/array/endless_array.rb
121
+ - lib/mext/array/fill.rb
120
122
  - lib/mext/array/scalarop.rb
121
123
  - lib/mext/array/vectorize.rb
122
124
  - lib/mext/exceptions.rb