diff --git a/app/lib/region.rb b/app/lib/region.rb new file mode 100644 index 0000000..6bada9d --- /dev/null +++ b/app/lib/region.rb @@ -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 diff --git a/app/services/esios/import.rb b/app/services/esios/import.rb index 27083d0..c22279e 100644 --- a/app/services/esios/import.rb +++ b/app/services/esios/import.rb @@ -5,7 +5,7 @@ def indicator_id end def geo_id - Rails.configuration.x.esios.zone + Region.current.esios end end end diff --git a/config/application.rb b/config/application.rb index c563939..a835e13 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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) diff --git a/config/locales/es.yml b/config/locales/es.yml index 521743d..426e788 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,2 +1,8 @@ es: - hello: "Hola mundo!" + regions: + pen: "Península" + can: "Islas Canarias" + bal: "Islas Baleares" + ceu: "Ceuta" + mel: "Melilla" + diff --git a/test/lib/region_test.rb b/test/lib/region_test.rb new file mode 100644 index 0000000..5e09db0 --- /dev/null +++ b/test/lib/region_test.rb @@ -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