Class: Parser::ComponentChooser

Inherits:
Object
  • Object
show all
Defined in:
lib/ngi/parser.rb

Overview

Abstraction to choose the component (custom or default)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ComponentChooser

Returns a new instance of ComponentChooser.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ngi/parser.rb', line 31

def initialize(args)
  chosen_type = -> (c) { c['name'] == args[:type] }
  @component = args[:components_hash].find(&chosen_type)

  return unless args[:config_hash].key? 'templates'

  custom = args[:config_hash]['templates'].find(&chosen_type)
  language = args[:config_hash]['language'].collect { |_, v| v }

  return if custom.nil?

  template = custom['templates']
             .find { |t| language.include? t['language'] }

  return if template.nil?

  template = template['template']
  # Rebuild the object to be used by Delegate::Generator
  custom = {
    'type' => custom['type'], 'using' => 'user',
    'template' => template, 'name' => custom['name']
  }

  @component = custom
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



29
30
31
# File 'lib/ngi/parser.rb', line 29

def component
  @component
end