Skip to content

Instantly share code, notes, and snippets.

@mizoR
Created June 15, 2013 05:59
Show Gist options
  • Save mizoR/5787099 to your computer and use it in GitHub Desktop.
Save mizoR/5787099 to your computer and use it in GitHub Desktop.
require 'mappie'
class Address
attr_accessor :pref_id
include Mappie
mappie :pref
def initialize(params={})
@pref_id = params[:pref_id]
end
end
source :rubygems
gem 'mappie', github: 'mizoR/mappie'
# -*- coding: utf-8 -*-
require './address'
require './pref'
Address.new(:pref_id => 10).pref #=> <Pref:0x007fafe333dfc0 @id=10, @name="群馬県">
Address.new(:pref_id => 15).pref #=> <Pref:0x007fafe333de30 @id=15, @name="新潟県">
Address.new(:pref_id => 20).pref #=> <Pref:0x007fafe333dca0 @id=20, @name="山梨県">
# -*- coding: utf-8 -*-
class Pref
attr_accessor :id, :name
def initialize(params={})
@id = params[:id]
@name = params[:name]
end
class << self
include Enumerable
def each
@_prefs.each do |pref|
yield pref
end
end
end
PREFS = %w(
北海道
青森県
岩手県
秋田県
宮城県
山形県
福島県
茨城県
栃木県
群馬県
埼玉県
千葉県
東京都
神奈川県
新潟県
福井県
石川県
富山県
静岡県
山梨県
長野県
愛知県
岐阜県
三重県
和歌山県
滋賀県
奈良県
京都府
大阪府
兵庫県
岡山県
広島県
鳥取県
島根県
山口県
香川県
徳島県
愛媛県
高知県
福岡県
佐賀県
長崎県
大分県
熊本県
宮崎県
鹿児島県
沖縄県)
@_prefs = PREFS.map.with_index do |name, i|
Pref.new(:id => i + 1, :name => name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment