serialnumber 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -43,8 +43,8 @@ spec = Gem::Specification.new do |s|
43
43
  s.authors = ["David Krentzlin"]
44
44
  s.email = ["david.krentzlin@lisp-unleashed.de"]
45
45
  s.homepage = ""
46
- s.summary = %q{Implementation of a rfc1982 serial}
47
- s.description = %q{Serialarithmetic as described in rfc1982}
46
+ s.summary = %q{Implementation of rfc1982}
47
+ s.description = %q{Arithmetic on serialnumbers as described in rfc1982}
48
48
 
49
49
  s.rubyforge_project = ""
50
50
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
@@ -24,19 +24,18 @@ module Serial
24
24
 
25
25
  class OutOfBound < RuntimeError; end
26
26
  class Invalid < RuntimeError; end
27
-
28
- # For some serial-numbers a comparision is
29
- # simply not defined. In this case an Exception of this
30
- # kind will be raised
31
- class ComparisonImpossible < RuntimeError; end
32
27
 
33
28
  # This class implements a serialnumber with it's operations as
34
29
  # described in rfc1982. This may for example be used to manage
35
- # serials as present in SOA-Records
30
+ # the serial part of SOA-Records.
31
+ #
32
+ # It defines only two basic operation; addition and comparison.
33
+ # Note that due to wrap-arounds you might encounter interesting
34
+ # results if you increment the serialnumber.
35
+ # As serialnumber may wrap the following expression may not always
36
+ # hold:
37
+ # sn > sn2 => (sn + 1) > sn2
36
38
  #
37
- # It defines only one basic operation, that is adding a fixnum.
38
- # It is does also define an order.
39
- #
40
39
  # == Examples
41
40
  # sn = Serial::RFC1982.new(100)
42
41
  # sn2 = sn + 12
@@ -47,18 +46,16 @@ module Serial
47
46
  attr_reader :serial_bits,:value
48
47
 
49
48
  # Creates a serialnumber object from the fixnum given
50
- # * the serial_bits define the domain of integers that can be
51
- # represented with the fixnum.
52
49
  def initialize(number,serial_bits = 32)
53
- raise OutOfBound,"The number of serial_bits must be >= 2" unless serial_bits >= 2
50
+ raise OutOfBound,"The number of serial_bits must be >= 1" unless serial_bits >= 1
51
+ ensure_valid_serial!(number,serial_bits)
54
52
  @serial_bits = serial_bits
55
- ensure_valid!(number)
56
- @value = number
53
+ @value = number
57
54
  end
58
55
 
59
56
  # Add a fixnum value to the serialnumber.
60
- # Note that the resulting value may be smaller than
61
- # the initial value due to a wrap-around on the serial-bits boundary
57
+ # Not that this may actually wrap if it exceeds the serialnumber's
58
+ # boundary given by serial_bits
62
59
  def +(number)
63
60
  if summand_out_of_bound?(number)
64
61
  raise OutOfBound,"The summand #{number} is out of bound"
@@ -78,15 +75,14 @@ module Serial
78
75
  protected
79
76
  def <=>(other)
80
77
  unless other.respond_to?(:value)
81
- raise Invalid,"Expected #{other} to respond_to :value"
78
+ raise Invalid,"Expected #{other} to respond to #value"
82
79
  end
83
80
  return 0 if equal?(value,other.value)
84
81
  return -1 if less?(value,other.value)
85
82
  return 1 if greater?(value,other.value)
86
- raise ComparisonImpossible, "The comparison is undefined"
87
83
  end
88
84
 
89
- def ensure_valid!(number)
85
+ def ensure_valid_serial!(number,serial_bits)
90
86
  raise Invalid,"Serial must be a fixnum" unless %w(Fixnum Bignum).include?(number.class.name)
91
87
  raise OutOfBound,"Negative numbers are not allowd" if number < 0
92
88
  if bits_needed_for(number) > serial_bits
data/serialnumber.gemspec CHANGED
@@ -2,19 +2,19 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{serialnumber}
5
- s.version = "0.0.11"
5
+ s.version = "0.0.12"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["David Krentzlin"]
9
- s.date = %q{2011-07-14}
10
- s.description = %q{Serialarithmetic as described in rfc1982}
9
+ s.date = %q{2011-07-15}
10
+ s.description = %q{Arithmetic on serialnumbers as described in rfc1982}
11
11
  s.email = ["david.krentzlin@lisp-unleashed.de"]
12
12
  s.files = [".hgignore", ".hgtags", "Gemfile", "Gemfile.lock", "README", "Rakefile", "VERSION", "autotest/discover.rb", "lib/serialnumber.rb", "lib/serialnumber/rfc1982.rb", "serialnumber.gemspec", "spec/serial_spec.rb", "spec/spec_helper.rb"]
13
13
  s.homepage = %q{}
14
14
  s.require_paths = ["lib"]
15
15
  s.rubyforge_project = %q{}
16
16
  s.rubygems_version = %q{1.3.7}
17
- s.summary = %q{Implementation of a rfc1982 serial}
17
+ s.summary = %q{Implementation of rfc1982}
18
18
  s.test_files = ["spec/serial_spec.rb", "spec/spec_helper.rb"]
19
19
 
20
20
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serialnumber
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Krentzlin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-14 00:00:00 +02:00
18
+ date: 2011-07-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: "0"
89
89
  type: :runtime
90
90
  version_requirements: *id005
91
- description: Serialarithmetic as described in rfc1982
91
+ description: Arithmetic on serialnumbers as described in rfc1982
92
92
  email:
93
93
  - david.krentzlin@lisp-unleashed.de
94
94
  executables: []
@@ -144,7 +144,7 @@ rubyforge_project: ""
144
144
  rubygems_version: 1.3.7
145
145
  signing_key:
146
146
  specification_version: 3
147
- summary: Implementation of a rfc1982 serial
147
+ summary: Implementation of rfc1982
148
148
  test_files:
149
149
  - spec/serial_spec.rb
150
150
  - spec/spec_helper.rb