Class: TaxJp::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/tax_jp/address.rb

Overview

減価償却率

Constant Summary collapse

DB_PATH =
File.join(TaxJp::Utils.data_dir, '住所.db')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Address

Returns a new instance of Address.



13
14
15
16
17
18
19
# File 'lib/tax_jp/address.rb', line 13

def initialize(row)
  @zip_code = row[0]
  @prefecture_code = row[1]
  @prefecture_name = row[2]
  @city = row[3]
  @section = row[4]
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



11
12
13
# File 'lib/tax_jp/address.rb', line 11

def city
  @city
end

#prefecture_codeObject (readonly)

Returns the value of attribute prefecture_code.



10
11
12
# File 'lib/tax_jp/address.rb', line 10

def prefecture_code
  @prefecture_code
end

#prefecture_nameObject (readonly)

Returns the value of attribute prefecture_name.



10
11
12
# File 'lib/tax_jp/address.rb', line 10

def prefecture_name
  @prefecture_name
end

#sectionObject (readonly)

Returns the value of attribute section.



11
12
13
# File 'lib/tax_jp/address.rb', line 11

def section
  @section
end

#zip_codeObject (readonly)

Returns the value of attribute zip_code.



9
10
11
# File 'lib/tax_jp/address.rb', line 9

def zip_code
  @zip_code
end

Class Method Details

.find_by_zip_code(zip_code) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tax_jp/address.rb', line 21

def self.find_by_zip_code(zip_code)
  zip_code = TaxJp::Utils.convert_to_zip_code(zip_code)

  TaxJp::Utils.with_database(DB_PATH) do |db|
    sql =  'select * from addresses '
    sql << 'where zip_code = ? '

    ret = nil
    db.execute(sql, [zip_code]) do |row|
      ret = TaxJp::Address.new(row)
    end
    ret
  end
end