class Kamome::Transformations::JigyoshoCsv

Transform a JIGYOSHO csv row to a Hash or others

Constants

VALID_ROW_SIZE

Public Instance Methods

generate_detail_model(row) click to toggle source

Generate an instance of Kamome::Models::Jigyosho from a JIGYOSHO csv row @return [Kamome::Models::Jigyosho]

# File lib/kamome/transformations/jigyosho_csv.rb, line 22
def generate_detail_model(row)
  attributes = generate_hash(row)
  ::Kamome::Models::Jigyosho.new(attributes)
end
generate_hash(row) click to toggle source

Generate a Hash from a JIGYOSHO csv row @return [Hash]

# File lib/kamome/transformations/jigyosho_csv.rb, line 15
def generate_hash(row)
  validate_row!(row)
  transform(row)
end
generate_model(row) click to toggle source

Generate an instance of Kamome::Models::Address from a JIGYOSHO csv row @return [Kamome::Models::Address]

# File lib/kamome/transformations/jigyosho_csv.rb, line 29
def generate_model(row)
  attributes = extract(generate_hash(row))
  ::Kamome::Models::Address.new(attributes)
end

Private Instance Methods

convert_state(state) click to toggle source
# File lib/kamome/transformations/jigyosho_csv.rb, line 77
def convert_state(state)
  state == 5 ? 2 : state
end
extract(attributes) click to toggle source
# File lib/kamome/transformations/jigyosho_csv.rb, line 62
def extract(attributes)
  {
    code: attributes[:code],
    zipcode: attributes[:zipcode],
    prefecture: attributes[:prefecture],
    city: attributes[:city],
    town: attributes[:town],
    street: attributes[:street],
    company_name: attributes[:company_name],
    post_office_box: attributes[:post_office_box],
    state: convert_state(attributes[:state]),
    ambiguous_town: false
  }
end
transform(row) click to toggle source
# File lib/kamome/transformations/jigyosho_csv.rb, line 44
def transform(row) # rubocop:disable Metrics/AbcSize
  {
    code: row[0].to_s,
    company_name_kana: row[1].to_s,
    company_name: row[2].to_s,
    prefecture: row[3].to_s,
    city: row[4].to_s,
    town: row[5].to_s,
    street: extract_street(row[6].to_s),
    post_office_box: extract_post_office_box(row[6].to_s),
    zipcode: row[7].to_s,
    japanpost_office_name: row[9].to_s,
    has_post_office_box: row[10].to_i == 1,
    multiple: row[11].to_i,
    state: row[12].to_i
  }
end
validate_row!(row) click to toggle source
# File lib/kamome/transformations/jigyosho_csv.rb, line 38
def validate_row!(row)
  return if row&.size == VALID_ROW_SIZE

  raise ArgumentError, "Wrong row size (expected #{VALID_ROW_SIZE}, got #{row&.size})"
end