Class: GeoMasterJp::Line

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/geo_master_jp/line.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(child) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/geo_master_jp/line.rb', line 25

def self.inherited(child)
  child.belongs_to :railway_company, class_name: GeoMasterJp.config.alternative_class_name(:railway_company), foreign_key: :geo_master_jp_railway_company_code, primary_key: :code
  child.has_many   :stations,        class_name: GeoMasterJp.config.alternative_class_name(:station),         foreign_key: :geo_master_jp_line_code,            primary_key: :code

  if GeoMasterJp.config.use_models.include?(:area)
    child.has_many :prefectures_lines, class_name: GeoMasterJp.config.alternative_class_name(:prefectures_line), foreign_key: :geo_master_jp_line_code, primary_key: :code
    child.has_many :prefectures, through: :prefectures_lines, class_name: GeoMasterJp.config.alternative_class_name(:prefecture)
  end

  super
end

.select_options(transactions = nil) ⇒ Object



41
42
43
# File 'app/models/geo_master_jp/line.rb', line 41

def self.select_options(transactions=nil)
  (transactions || all).map{|line| [line.name, line.code] }
end

Instance Method Details

#head_kanaObject



19
20
21
22
23
# File 'app/models/geo_master_jp/line.rb', line 19

def head_kana
  return '' if self.name_kana.blank?
  head_kanas = ['', '', '', '', '', '', '', '', '', '']
  head_kanas[head_kanas.index{|i| i > self.name_kana[0] }.to_i - 1]
end

#station_select_optionsObject



37
38
39
# File 'app/models/geo_master_jp/line.rb', line 37

def station_select_options
  self.stations.map{|station| [station.name, station.code] }
end