Skip to content

Commit

Permalink
Merge pull request #90 from javierav/feature/region
Browse files Browse the repository at this point in the history
Add Region class
  • Loading branch information
javierav authored Jan 22, 2024
2 parents 3417d5b + 4fd5cbe commit 9221257
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
23 changes: 23 additions & 0 deletions app/lib/region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Region
attr_reader :id

def self.current
new(Rails.configuration.x.region)
end

def initialize(id)
@id = id.to_i
end

def name
I18n.t(key, scope: "regions")
end

def key
%w[pen can bal ceu mel][id - 1]
end

def esios
[8741, 8742, 8743, 8744, 8745][id - 1]
end
end
2 changes: 1 addition & 1 deletion app/services/esios/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def indicator_id
end

def geo_id
Rails.configuration.x.esios.zone
Region.current.esios
end
end
end
8 changes: 5 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ class Application < Rails::Application
# Application Timezone
config.time_zone = ENV.fetch("TZ", "Europe/Madrid")

# Application Region
config.x.region = ENV.fetch("SOLARIS_REGION", "1").to_i

# Intervals
config.x.intervals.loop = ENV.fetch("SOLARIS_LOOP_INTERVAL", 30).to_i
config.x.intervals.archive = ENV.fetch("SOLARIS_ARCHIVE_INTERVAL", 300).to_i
config.x.intervals.loop = ENV.fetch("SOLARIS_LOOP_INTERVAL", "30").to_i
config.x.intervals.archive = ENV.fetch("SOLARIS_ARCHIVE_INTERVAL", "300").to_i

# ESIOS
config.x.esios.api_key = ENV.fetch("ESIOS_API_KEY", nil)
config.x.esios.zone = ENV.fetch("ESIOS_ZONE", 8741)

# Protocol
config.x.protocol = ENV.fetch("SOLARIS_PROTOCOL", nil)
Expand Down
8 changes: 7 additions & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
es:
hello: "Hola mundo!"
regions:
pen: "Península"
can: "Islas Canarias"
bal: "Islas Baleares"
ceu: "Ceuta"
mel: "Melilla"

55 changes: 55 additions & 0 deletions test/lib/region_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require "test_helper"

class RegionTest < ActiveSupport::TestCase
test "with default region" do
assert_equal 1, Region.current.id
assert_equal "pen", Region.current.key
assert_equal "Península", Region.current.name
assert_equal 8741, Region.current.esios
end

test "with region 1" do
Rails.configuration.x.with(region: 1) do
assert_equal 1, Region.current.id
assert_equal "pen", Region.current.key
assert_equal "Península", Region.current.name
assert_equal 8741, Region.current.esios
end
end

test "with region 2" do
Rails.configuration.x.with(region: 2) do
assert_equal 2, Region.current.id
assert_equal "can", Region.current.key
assert_equal "Islas Canarias", Region.current.name
assert_equal 8742, Region.current.esios
end
end

test "with region 3" do
Rails.configuration.x.with(region: 3) do
assert_equal 3, Region.current.id
assert_equal "bal", Region.current.key
assert_equal "Islas Baleares", Region.current.name
assert_equal 8743, Region.current.esios
end
end

test "with region 4" do
Rails.configuration.x.with(region: 4) do
assert_equal 4, Region.current.id
assert_equal "ceu", Region.current.key
assert_equal "Ceuta", Region.current.name
assert_equal 8744, Region.current.esios
end
end

test "with region 5" do
Rails.configuration.x.with(region: 5) do
assert_equal 5, Region.current.id
assert_equal "mel", Region.current.key
assert_equal "Melilla", Region.current.name
assert_equal 8745, Region.current.esios
end
end
end

0 comments on commit 9221257

Please sign in to comment.