Class: It::Interpolation

Inherits:
Object
  • Object
show all
Defined in:
lib/it/interpolation.rb

Overview

Contains one interpolation and will delegate the work to the It::Tag (or subclass) or ERB::Util.h

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, label) ⇒ Interpolation

Returns a new instance of Interpolation.



24
25
26
27
28
# File 'lib/it/interpolation.rb', line 24

def initialize(key, value, label)
  @key = key
  @value = value
  @label = label
end

Class Method Details

.call(string, values) ⇒ Object

Raises:

  • (KeyError)


6
7
8
9
10
11
12
13
# File 'lib/it/interpolation.rb', line 6

def call(string, values)
  key, label = extract_key_and_label_from(string)
  value = values[key]

  raise KeyError, "key{#{key}} not found" unless values.key?(key)

  new(key, value, label).process
end

Instance Method Details

#processObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/it/interpolation.rb', line 30

def process
  convert_link

  validate_value_for_arguments

  if value.is_a?(It::Tag)
    process_it_tag
  else # Normal interpolations, as I18n.t would do it.
    ERB::Util.h(value)
  end
end