Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 63 additions and 0 deletions.
  1. +4 −0 app.rb
  2. +59 −0 lib/prefecture.rb
View
4 app.rb
@@ -0,0 +1,4 @@
+require './lib/prefecture'
+
+get '/' do
+end
View
59 lib/prefecture.rb
@@ -0,0 +1,59 @@
+require 'csv'
+
+class Prefecture
+
+ attr_reader :id
+ attr_reader :name
+ attr_reader :name_j
+ attr_reader :capital
+ attr_reader :capital_j
+ attr_reader :iso
+ attr_reader :region
+ attr_reader :island
+ attr_reader :area
+ attr_reader :population
+
+ class << self
+
+ def all
+ @prefectures ||= load_prefectures
+ end
+
+ private
+
+ def load_prefectures
+ options = {
+ :headers => true,
+ :header_converters => :symbol,
+ :converters => :numeric,
+ :encoding => "UTF-8"
+ }
+
+ prefectures = []
+ CSV.foreach(settings.prefectures_file, options) do |row|
+ prefectures << Prefecture.new(row)
+ end
+
+ prefectures
+ end
+
+ end
+
+ def initialize row
+ @id = row[:id]
+ @name = row[:name]
+ @name_j = row[:name_j]
+ @capital = row[:capital]
+ @capital_j = row[:capital_j]
+ @iso = row[:iso]
+ @region = row[:region]
+ @island = row[:island]
+ @area = row[:area]
+ @population = row[:population]
+ end
+
+ def density
+ population / area
+ end
+
+end

No commit comments for this range

Something went wrong with that request. Please try again.