class JapanETC::DatabaseProvider::BaseNEXCO
Constants
- IDENTIFIER_PATTERN
- ROAD_NAME_PATTERN
- TOLLBOOTH_LINE_PATTERN
- WHITESPACE
Attributes
current_road_name[R]
current_route_name[R]
current_tollbooth_name[R]
Public Instance Methods
canonicalize(road_name)
click to toggle source
# File lib/japan_etc/database_provider/base_nexco.rb, line 105 def canonicalize(road_name) road_name = '首都圏中央連絡自動車道' if road_name == '首都圏中央連絡道' road_name = road_name.sub(/高速\z/, '高速道路') road_name end
extract_route_name_from_road_name(road_name)
click to toggle source
# File lib/japan_etc/database_provider/base_nexco.rb, line 98 def extract_route_name_from_road_name(road_name) road_name = normalize(road_name) match = road_name.match(/\A(?<road_name>.+?)(?<route_name>\d+号.+)?\z/) road_name = match[:road_name].sub(/高速\z/, '高速道路') [road_name, match[:route_name]] end
fetch_tollbooths()
click to toggle source
# File lib/japan_etc/database_provider/base_nexco.rb, line 59 def fetch_tollbooths tollbooths = [] lines.each do |line| break if line.include?('【更新リスト】') tollbooths << parse_line(line) end tollbooths.flatten.compact end
lines()
click to toggle source
# File lib/japan_etc/database_provider/base_nexco.rb, line 111 def lines pdf.pages.flat_map { |page| page.text.each_line.map(&:chomp).to_a } end
parse_line(line)
click to toggle source
# File lib/japan_etc/database_provider/base_nexco.rb, line 71 def parse_line(line) match = line.match(TOLLBOOTH_LINE_PATTERN) return unless match if match[:road_name] road_name = remove_whitespaces(normalize(match[:road_name])) @current_road_name, @current_route_name = extract_route_name_from_road_name(road_name) @current_road_name = canonicalize(@current_road_name) end @current_tollbooth_name = match[:tollbooth_name] if match[:tollbooth_name] identifiers = match[:identifiers].scan(IDENTIFIER_PATTERN) identifiers.map do |identifier| Tollbooth.create( road_number: identifier.first, tollbooth_number: identifier.last, road_name: current_road_name, route_name: current_route_name, name: current_tollbooth_name, note: match[:note], source: source_id ) end end
pdf()
click to toggle source
# File lib/japan_etc/database_provider/base_nexco.rb, line 115 def pdf response = Faraday.get(source_url) PDF::Reader.new(StringIO.new(response.body)) end