Class: ScaffoldParser::Scaffolders::XSD::Parser::Handlers::SubmodelMethod

Inherits:
Object
  • Object
show all
Includes:
BaseMethod, Utils
Defined in:
lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb

Instance Attribute Summary collapse

Attributes included from BaseMethod

#source

Instance Method Summary collapse

Methods included from Utils

#indent, #indent_string, #single_quote, #wrap_in_namespace

Methods included from BaseMethod

#==, #method_name, #to_s

Constructor Details

#initialize(source, submodel_class = nil) ⇒ SubmodelMethod

Returns a new instance of SubmodelMethod.



12
13
14
15
16
17
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 12

def initialize(source, submodel_class = nil)
  @source = source
  @submodel_class =
    submodel_class ||
    source.type&.split(':')&.map(&:camelize)&.join('::')
end

Instance Attribute Details

#submodel_classObject

Returns the value of attribute submodel_class.



10
11
12
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 10

def submodel_class
  @submodel_class
end

Instance Method Details

#all(_) ⇒ Object



57
58
59
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 57

def all(_)
  All.new self
end

#atObject



19
20
21
22
23
24
25
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 19

def at
  if source.name
    [source.xmlns_prefix, "#{source.name}"].compact.join(':')
  elsif source.ref
    source.ref
  end
end

#choice(_) ⇒ Object



53
54
55
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 53

def choice(_)
  Choice.new self
end

#method_bodyObject



27
28
29
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 27

def method_body
  "submodel_at(#{submodel_class}, '#{at}')"
end

#name_with_prefixObject



31
32
33
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 31

def name_with_prefix
  [source.xmlns_prefix, "#{method_name}"].compact.join(':')
end

#schema(_) ⇒ Object



61
62
63
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 61

def schema(_)
  STACK
end

#sequence(_) ⇒ Object



49
50
51
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 49

def sequence(_)
  Sequence.new self
end

#to_at_methodObject



65
66
67
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 65

def to_at_method
  AtMethod.new(source)
end

#to_builderObject



39
40
41
42
43
44
45
46
47
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 39

def to_builder
  f = StringIO.new

  f.puts "if data.key? :#{method_name}"
  f.puts "  root << #{submodel_class}.new('#{at}', data[:#{method_name}]).builder"
  f.puts 'end'

  f.string.strip
end

#to_h_methodObject



35
36
37
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/submodel_method.rb', line 35

def to_h_method
  "hash[:#{method_name}] = #{method_name}.to_h if has? '#{at}'"
end