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:



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/japan_etc/tollbooth.rb', line 240

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



236
237
238
# File 'lib/japan_etc/tollbooth.rb', line 236

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

Instance Method Details

#<=>(other) ⇒ Object



256
257
258
# File 'lib/japan_etc/tollbooth.rb', line 256

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

#to_sObject



252
253
254
# File 'lib/japan_etc/tollbooth.rb', line 252

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