Class: EaSSL::Serial

Inherits:
Object
  • Object
show all
Defined in:
lib/eassl/serial.rb

Overview

Author

Chris Andrews ([email protected])

Copyright

Copyright © 2011 Chris Andrews

License

Distributes under the same terms as Ruby

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Serial

Returns a new instance of Serial.



8
9
10
11
# File 'lib/eassl/serial.rb', line 8

def initialize(options = {})
  @next = options[:next]
  @path = options[:path]
end

Instance Attribute Details

#nextObject (readonly)

Returns the value of attribute next.



7
8
9
# File 'lib/eassl/serial.rb', line 7

def next
  @next
end

Class Method Details

.load(serial_file_path) ⇒ Object



13
14
15
16
# File 'lib/eassl/serial.rb', line 13

def self.load(serial_file_path)
  hex_string = (File.read(serial_file_path))
  self.new(:next => Integer("0x#{hex_string}"), :path => serial_file_path)
end

Instance Method Details

#issue_serialObject



27
28
29
30
# File 'lib/eassl/serial.rb', line 27

def issue_serial
  @next = @next + 1
  @next - 1
end

#save!Object



18
19
20
21
22
23
24
25
# File 'lib/eassl/serial.rb', line 18

def save!
  if @path
    hex_string = sprintf("%04X", @next)
    File.open(@path, 'w') do |io|
      io.write "#{hex_string}\n"
    end
  end
end