Class: Metanorma::Plugin::Lutaml::Liquid::CustomBlocks::KeyIterator
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Metanorma::Plugin::Lutaml::Liquid::CustomBlocks::KeyIterator
- Defined in:
- lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ KeyIterator
constructor
A new instance of KeyIterator.
-
#render(context) ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ KeyIterator
Returns a new instance of KeyIterator.
7 8 9 10 |
# File 'lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb', line 7 def initialize(tag_name, markup, tokens) super @context_name, @var_name = markup.split(",").map(&:strip) end |
Instance Method Details
#render(context) ⇒ Object
rubocop:disable Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/metanorma/plugin/lutaml/liquid/custom_blocks/key_iterator.rb', line 12 def render(context) # rubocop:disable Metrics/MethodLength res = "" iterator = if context[@context_name].is_a?(Hash) context[@context_name].keys else context[@context_name] end iterator.each.with_index do |key, index| context["index"] = index context[@var_name] = key res += super end res end |