sim_kind.rb

 1# frozen_string_literal: true
 2
 3class SIMKind
 4	attr_reader :klass
 5
 6	def initialize(variant)
 7		@klass =
 8			case variant
 9			when "sim"
10				SIMOrder
11			when "esim"
12				SIMOrder::ESIM
13			end
14		@variant = variant
15	end
16
17	def self.from_form(form)
18		new(form.field("sim_kind")&.value)
19	end
20
21	def cfg(currency)
22		CONFIG.dig(:sims, @variant.to_sym, currency)
23	end
24
25	def price_dollars(currency)
26		cfg = cfg(currency)
27		return nil unless cfg
28
29		cfg[:price] / 100.to_d
30	end
31end