wave_int 0.1.1 → 1.0.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
  SHA1:
3
- metadata.gz: 673dff3f58a8117bb67c582c3e6b812bb7f09b63
4
- data.tar.gz: 6981a6d2b6eb707b4e9ada53155f9d6906f16c20
3
+ metadata.gz: 195553454c64e244b5ac181aef248481827d1495
4
+ data.tar.gz: 81cc7d1b360c969f335dafdca3a834638fc69126
5
5
  SHA512:
6
- metadata.gz: af2b90629a8ab3eb3bcec9fbd398ec8d01a6e69365ae83f3a2cc5c12db524adad99814cf6ca98dd27c49de3eb71ac38379d4ad3df91245b3c4d213e2587d3c60
7
- data.tar.gz: 77c46a78583426d387ab67efe81f799a7d5e1fdd01b3de552eded382842274f6de33569cc59f25766297f4925d621babe74abc1c79601b81aeb4f5cf5010812a
6
+ metadata.gz: 9d6836c68509f29cd0aa4e1dbb1fa0abce2d65da32a4308bd8ea8f477079ad7c8d593763c9137bbe8b334dba0589bfd02bb2f2f493ddc8b107e27d03896c6520
7
+ data.tar.gz: 9de483579ef2503c4bda0d46bf89f105afa4ba44f86b5a49c8f8ace336c124df44297e859854041622ea8d11cd516b3db46a6db5f3fe32734d3a5c8708ed8548
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # WaveInt
2
2
 
3
- WaveInt
3
+ WaveInt class generate linear gradient value in the range.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,20 +20,40 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- For example, get wave value from -2 to 2
23
+ For example, get wave value from -10 to 10
24
24
 
25
25
  ```ruby
26
- wave = WaveInt.new(-2, 2)
27
- wave_array = 10.times.map {|v| wave.value(v) }
28
- #=> [0, 1, 2, 1, 0, -1, -2, -1, 0, 1]
26
+ wave = WaveInt.new(-10, 10)
27
+ wave.value(9) #=> 9
28
+ wave.value(10) #=> 10
29
+ wave.value(11) #=> 9
30
+ wave.value(20) #=> 0
31
+ wave.value(21) #=> -1
32
+ wave.value(30) #=> -10
33
+ wave.value(31) #=> -9
29
34
  ```
30
35
 
31
36
  The order of parameters is redundant, and second parameter can be omit(default: 0).
32
37
 
33
38
  ```ruby
34
- wave = WaveInt.new(3)
35
- wave_array = 8.times.map {|V| wave.value(v) }
36
- #=> [0, 1, 2, 3, 2, 1, 0, 8]
39
+ wave = WaveInt.new(5)
40
+ wave_array = 8.times.map {|v| wave.value(v) }
41
+ #=> [0, 1, 2, 3, 4, 5, 4, 3]
42
+ ```
43
+
44
+ More simply, wave controll with repeat,
45
+ use WaveInt#set_value and WaveInt#add.
46
+
47
+ ```ruby
48
+ wave = WaveInt.new(5, -2)
49
+ wave_array = 8.times.map {|v| wave.add(3) }
50
+ #=> [3, 4, 1, -2, 1, 4, 3, 0]
51
+
52
+ # if you need reset(or set start value), use set_value.
53
+ wave.set_value(0)
54
+ wave.add(2) #=> 2
55
+ wave.set_value(5)
56
+ wave.add(6) #=> -1
37
57
  ```
38
58
 
39
59
  ## Development
data/lib/wave_int.rb CHANGED
@@ -4,14 +4,24 @@ class WaveInt
4
4
  # Set WaveInt Range.
5
5
  def initialize(limit1, limit2=0)
6
6
  @min, @max = [limit1.to_i, limit2.to_i].sort
7
- @v = @min
7
+ @value = @min
8
8
  end
9
9
 
10
- # Get WaveInt Value.(default: return last value)
11
- def value(number = @v)
12
- n = (number.to_i - offset) % (cycle)
13
- @v = offset + (n < wave_max ? n : cycle - n)
14
- @v
10
+ # Get WaveInt Value.(default: return now value)
11
+ def value(number = @value)
12
+ n = (number.to_i - offset) % cycle
13
+ offset + (n < wave_max ? n : cycle - n)
14
+ end
15
+
16
+ # Set WaveInt Value, and return WaveInt value.
17
+ def set_value(number)
18
+ @value = offset + (number.to_i - offset) % cycle
19
+ value
20
+ end
21
+
22
+ # Get WaveInt next value.
23
+ def add(number)
24
+ set_value(@value + number.to_i)
15
25
  end
16
26
 
17
27
  private
@@ -1,3 +1,3 @@
1
1
  class WaveInt
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/wave_int.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Generate linear gradient value.}
13
13
  spec.description = %q{WaveInt class Generate linear gradient value in the range.}
14
- spec.homepage = ""
14
+ spec.homepage = "https://github.com/garowolflex/wave_int"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wave_int
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - garowolflex
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,7 +71,7 @@ files:
71
71
  - lib/wave_int.rb
72
72
  - lib/wave_int/version.rb
73
73
  - wave_int.gemspec
74
- homepage: ''
74
+ homepage: https://github.com/garowolflex/wave_int
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}