Sha256: 53be4f37cd95c9921202b8dc4fd90aeee7f31b0c4825a64c72088378147461db

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module ScaffoldParser
  module Scaffolders
    class XSD
      class Parser
        module Handlers
          class ProxyListMethod
            include BaseMethod
            include Utils

            attr_accessor :at, :item_class

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

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

            def to_h_with_attrs_method
              if item_class == 'String'
                "hash[:#{method_name}] = #{method_name} if has? '#{source.name}'"
              else
                "hash[:#{method_name}] = #{method_name}.map(&:to_h_with_attrs) if has? '#{source.name}'"
              end
            end

            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

            def sequence(_)
              Sequence.new self
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scaffold_parser-0.6.0 lib/scaffold_parser/scaffolders/xsd/parser/handlers/proxy_list_method.rb