Class: JapanETC::Tollbooth
- Inherits:
-
Object
- Object
- JapanETC::Tollbooth
- Includes:
- Comparable, Util
- Defined in:
- lib/japan_etc/tollbooth.rb
Defined Under Namespace
Classes: Identifier
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#entrance_or_exit ⇒ Object
Returns the value of attribute entrance_or_exit.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#road ⇒ Object
Returns the value of attribute road.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(identifier:, road:, name:, direction:, entrance_or_exit:, note:, source:, priority:) ⇒ Tollbooth
constructor
A new instance of Tollbooth.
- #initialize_copy(original) ⇒ Object
- #obsolete? ⇒ Boolean
- #to_a ⇒ Object
Methods included from Util
convert_fullwidth_characters_to_halfwidth, convert_to_integer, normalize, remove_whitespaces
Constructor Details
#initialize(identifier:, road:, name:, direction:, entrance_or_exit:, note:, source:, priority:) ⇒ Tollbooth
Returns a new instance of Tollbooth.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/japan_etc/tollbooth.rb', line 44 def initialize( identifier:, road:, name:, direction:, entrance_or_exit:, note:, source:, priority: ) raise ValidationError if identifier.nil? || road.nil? || name.nil? @identifier = identifier @road = road @name = remove_whitespaces(normalize(name)) @direction = direction @entrance_or_exit = entrance_or_exit @notes = [] notes << normalize(note) if note @source = source @priority = priority normalize! end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def direction @direction end |
#entrance_or_exit ⇒ Object
Returns the value of attribute entrance_or_exit.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def entrance_or_exit @entrance_or_exit end |
#identifier ⇒ Object
Returns the value of attribute identifier.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def identifier @identifier end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def name @name end |
#notes ⇒ Object
Returns the value of attribute notes.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def notes @notes end |
#priority ⇒ Object
Returns the value of attribute priority.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def priority @priority end |
#road ⇒ Object
Returns the value of attribute road.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def road @road end |
#source ⇒ Object
Returns the value of attribute source.
14 15 16 |
# File 'lib/japan_etc/tollbooth.rb', line 14 def source @source end |
Class Method Details
.create(road_number:, tollbooth_number:, road_name:, route_name: nil, name:, direction: nil, entrance_or_exit: nil, note: nil, source: nil, priority: 0) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/japan_etc/tollbooth.rb', line 17 def self.create( road_number:, tollbooth_number:, road_name:, route_name: nil, name:, direction: nil, entrance_or_exit: nil, note: nil, source: nil, priority: 0 ) identifier = Identifier.new(road_number, tollbooth_number) road = Road.new(road_name, route_name) new( identifier: identifier, road: road, name: name, direction: direction, entrance_or_exit: entrance_or_exit, note: note, source: source, priority: priority ) end |
Instance Method Details
#<=>(other) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/japan_etc/tollbooth.rb', line 84 def <=>(other) result = identifier <=> other.identifier return result unless result.zero? result = priority <=> other.priority return -result unless result.zero? # Tollbooth with higher priority comes first return -1 if !obsolete? && other.obsolete? return 1 if obsolete? && !other.obsolete? i[road name source].each do |attribute| result = send(attribute) <=> other.send(attribute) return result unless result.zero? end 0 end |
#==(other) ⇒ Object Also known as: eql?
74 75 76 |
# File 'lib/japan_etc/tollbooth.rb', line 74 def ==(other) other.is_a?(self.class) && identifier == other.identifier end |
#hash ⇒ Object
80 81 82 |
# File 'lib/japan_etc/tollbooth.rb', line 80 def hash identifier.hash end |
#initialize_copy(original) ⇒ Object
69 70 71 72 |
# File 'lib/japan_etc/tollbooth.rb', line 69 def initialize_copy(original) @road = original.road.dup @name = original.name.dup end |
#obsolete? ⇒ Boolean
114 115 116 |
# File 'lib/japan_etc/tollbooth.rb', line 114 def obsolete? notes.any? { |note| note.include?('迄') } end |
#to_a ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/japan_etc/tollbooth.rb', line 102 def to_a [ identifier.to_s, road.to_a, name, direction, entrance_or_exit, notes.empty? ? nil : notes.join(' '), source ].flatten end |