Class: JapanETC::Tollbooth::Identifier

Inherits:
Struct
  • Object
show all
Includes:
Comparable, Util
Defined in:
lib/japan_etc/tollbooth.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

convert_fullwidth_characters_to_halfwidth, convert_to_integer, normalize, remove_whitespaces

Constructor Details

#initialize(road_number, tollbooth_number) ⇒ Identifier

Returns a new instance of Identifier.

Raises:



248
249
250
251
252
253
254
255
256
257
258
# File 'lib/japan_etc/tollbooth.rb', line 248

def initialize(road_number, tollbooth_number)
  road_number = convert_to_integer(road_number)
  raise ValidationError, '#road_number cannot be nil' if road_number.nil?
  raise ValidationError, '#road_number must be lower than 100' if road_number >= 100

  tollbooth_number = convert_to_integer(tollbooth_number)
  raise ValidationError, '#tollbooth_number cannot be nil' if tollbooth_number.nil?
  raise ValidationError, '#road_number must be lower than 1000' if tollbooth_number >= 1000

  super(road_number, tollbooth_number)
end

Class Method Details

.from(string) ⇒ Object



244
245
246
# File 'lib/japan_etc/tollbooth.rb', line 244

def self.from(string)
  new(*string.split('-'))
end

Instance Method Details

#<=>(other) ⇒ Object



264
265
266
# File 'lib/japan_etc/tollbooth.rb', line 264

def <=>(other)
  to_s <=> other.to_s
end

#to_sObject



260
261
262
# File 'lib/japan_etc/tollbooth.rb', line 260

def to_s
  @string ||= format('%02d-%03d', road_number, tollbooth_number)
end