Class: ScaffoldParser::Scaffolders::XSD::Parser::Handlers::ProxyListMethod

Inherits:
Object
  • Object
show all
Includes:
BaseMethod, Utils
Defined in:
lib/scaffold_parser/scaffolders/xsd/parser/handlers/proxy_list_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) {|_self| ... } ⇒ ProxyListMethod

Returns a new instance of ProxyListMethod.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(source)
  @source = source
  yield self if block_given?
end

Instance Attribute Details

#atObject

Returns the value of attribute at.



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

def at
  @at
end

#item_classObject

Returns the value of attribute item_class.



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

def item_class
  @item_class
end

Instance Method Details

#method_bodyObject



17
18
19
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/proxy_list_method.rb', line 17

def method_body
  "array_of_at(#{item_class}, #{single_quote(at)})"
end

#name_with_prefixObject



21
22
23
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/proxy_list_method.rb', line 21

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

#sequence(_) ⇒ Object



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

def sequence(_)
  Sequence.new self
end

#to_builderObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/proxy_list_method.rb', line 33

def to_builder
  f = StringIO.new

  f.puts "if data.key? :#{method_name}"
  f.puts "  element = Ox::Element.new('#{at.first}')"
  if item_class == 'String'
    f.puts "  data[:#{method_name}].map { |i| Ox::Element.new('#{at.last}') << i }.each { |i| element << i }"
  else
    f.puts "  data[:#{method_name}].each { |i| element << #{item_class}.new('#{at.last}', i).builder }"
  end
  f.puts '  root << element'
  f.puts 'end'

  f.string.strip
end

#to_h_methodObject



25
26
27
28
29
30
31
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/proxy_list_method.rb', line 25

def to_h_method
  if item_class == 'String'
    "hash[:#{method_name}] = #{method_name} if has? '#{name_with_prefix}'"
  else
    "hash[:#{method_name}] = #{method_name}.map(&:to_h) if has? '#{name_with_prefix}'"
  end
end