class Jisx0402::Code

Constants

ATTRS_INDEX
GOVERNMENT_ORDINANCE_DESIGNATED_CITY_CODE_LIST

Public Class Methods

new(row) click to toggle source
# File lib/jisx0402.rb, line 134
def initialize(row)
  @row = row
end

Public Instance Methods

code() click to toggle source
# File lib/jisx0402.rb, line 142
def code
  @row[0]
end
code_without_checkdigit() click to toggle source
# File lib/jisx0402.rb, line 146
def code_without_checkdigit
  code[0..-2]
end
cover?(c) click to toggle source
# File lib/jisx0402.rb, line 193
def cover?(c)
  return false if !c || c.size == 0

  area_code = c.to_s
  if prefecture?
    area_code.start_with?(prefecture_code)
  elsif government_ordinance_designated_city?
    Jisx0402.forward_match_by_full(full).codes.include?(area_code)
  else
    code == area_code
  end
end
district(hiragana: false) click to toggle source
# File lib/jisx0402.rb, line 177
def district(hiragana: false)
  hiragana ? @row[4] : @row[3]
end
district_code() click to toggle source
# File lib/jisx0402.rb, line 150
def district_code
  @district_code ||= code[2..4]
end
first() click to toggle source
# File lib/jisx0402.rb, line 185
def first
  self #compatible for Array#first
end
full(hiragana: false) click to toggle source
# File lib/jisx0402.rb, line 181
def full(hiragana: false)
  hiragana ? @row[6] : @row[5]
end
government_ordinance_designated_city?() click to toggle source
# File lib/jisx0402.rb, line 159
def government_ordinance_designated_city?
  @government_ordinance_designated_city ||= begin
    GOVERNMENT_ORDINANCE_DESIGNATED_CITY_CODE_LIST.include?(district_code)
  end
end
match?(word, by) click to toggle source
# File lib/jisx0402.rb, line 138
def match?(word, by)
  @row.at(ATTRS_INDEX.index(by.to_s)) =~ /#{word}/
end
prefecture(hiragana: false) click to toggle source
# File lib/jisx0402.rb, line 173
def prefecture(hiragana: false)
  hiragana ? @row[2] : @row[1]
end
prefecture?() click to toggle source
# File lib/jisx0402.rb, line 154
def prefecture?
  district_code == '000'.freeze
end
prefecture_code() click to toggle source
# File lib/jisx0402.rb, line 169
def prefecture_code
  code[0..1]
end
ward?() click to toggle source
# File lib/jisx0402.rb, line 165
def ward?
  @ward ||= (100..199).cover?(district_code.to_i)
end
zipcodes() click to toggle source
# File lib/jisx0402.rb, line 189
def zipcodes
  Jisx0402.jisx0402_to_zipcode_table[code_without_checkdigit] || []
end