class JapanETC::DatabaseProvider::MetropolitanExpressway
Constants
- DIRECTION_SUFFIX_PATTERN
- OPPOSITE_DIRECTIONS
Public Instance Methods
csv()
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 74 def csv shiftjis_csv.encode(Encoding::UTF_8) end
extract_direction_from_name!(tollbooth)
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 35 def extract_direction_from_name!(tollbooth) match = tollbooth.name.match(DIRECTION_SUFFIX_PATTERN) return unless match direction = match.to_s return if %w[東 西].include?(direction) && tollbooth.road.route_name != '湾岸線' opposite_name = tollbooth.name.sub(DIRECTION_SUFFIX_PATTERN, OPPOSITE_DIRECTIONS[direction]) opposite_tollbooth_exists = original_tollbooths.find do |other_tollbooth| other_tollbooth.road == tollbooth.road && other_tollbooth.name == opposite_name end return unless opposite_tollbooth_exists tollbooth.direction = Direction.from(direction) tollbooth.name.sub!(DIRECTION_SUFFIX_PATTERN, '') end
fetch_tollbooths()
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 27 def fetch_tollbooths original_tollbooths.map do |original_tollbooth| tollbooth = original_tollbooth.dup extract_direction_from_name!(tollbooth) tollbooth end end
original_tollbooths()
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 56 def original_tollbooths @original_tollbooths ||= rows.map do |row| Tollbooth.create( road_number: row[0], tollbooth_number: row[1], road_name: '首都高速道路', route_name: row[2], name: row[3], entrance_or_exit: EntranceOrExit.from(row[4]), source: source_id ) end end
rows()
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 70 def rows CSV.parse(csv, headers: :first_row) end
shiftjis_csv()
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 78 def shiftjis_csv response = Faraday.get(source_url) response.body.force_encoding(Encoding::Shift_JIS) end
source_url()
click to toggle source
# File lib/japan_etc/database_provider/metropolitan_expressway.rb, line 12 def source_url 'https://www.shutoko.jp/fee/tollbooth/~/media/pdf/customer/fee/tollbooth/code200322_.csv/' end