Class: I18nGenerator::Label
- Inherits:
-
Object
- Object
- I18nGenerator::Label
- Defined in:
- lib/i18n_generator/label.rb
Overview
Represents a text item for translation Instantiated with a hash of parameters Validates required parameters are present on creation Creates class variables and accessors for supplied parameters
Instance Method Summary collapse
-
#initialize(params_hash) ⇒ Label
constructor
A new instance of Label.
-
#validate_params(params) ⇒ Object
Ensures required parameters are present.
Constructor Details
#initialize(params_hash) ⇒ Label
Returns a new instance of Label.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/i18n_generator/label.rb', line 10 def initialize(params_hash) validate_params(params_hash) params_hash.each do |param, value| instance_variable_set("@#{param}", value) define_singleton_method param.to_sym do instance_variable_get("@#{param}") end end end |
Instance Method Details
#validate_params(params) ⇒ Object
Ensures required parameters are present
24 25 26 27 28 |
# File 'lib/i18n_generator/label.rb', line 24 def validate_params(params) %w(id en).map(&:to_sym).each do |req_param| raise "Label is missing required parameter [#{req_param}]" unless params[req_param] && !params[req_param].empty? end end |