Sha256: 01cea081235fba57291296e21f6f081ffce531dc43518c3a733640f91bf65ee2

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

module AssOle
  module Snippets
    #
    module Shared
      # @api private
      def self.mapped_mixin(module_)
        module_.instance_eval do
          define_method :_hash_to_object do |hash_, object_|
            hash_.each_with_object(object_) do |k_v, obj|
              key = (k_v[0].is_a?(Symbol) ? k_v[0].to_s : k_v[0])
              value = k_v[1]
              if value.nil?
                obj.Insert(key)
              else
                obj.Insert(key, value)
              end
            end
          end
          private :_hash_to_object
        end
      end

      # Snippet for worcking with 1C Map obect
      module Map
        Shared.mapped_mixin self
        # Returns new Map builded from hash
        # @note If +key.is_a? Symbol+ key will be converts to +String+
        # @return [WIN32OLE]
        def map(hash_ = nil, **hash__)
          hash_ = hash__ if hash_.nil?
          _hash_to_object(hash_, newObject('Map'))
        end
      end

      # Snippet for worcking with 1C Structure obect
      module Structure
        Shared.mapped_mixin self
        # Returns new Structure builded from hash
        # @note (see Map#map)
        # @return [WIN32OLE]
        def structure(hash_ = nil, **hash__)
          hash_ = hash__ if hash_.nil?
          _hash_to_object(hash_, newObject('Structure'))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ass_ole-snippets-shared-0.4.0 lib/ass_ole/snippets/shared/mapped.rb
ass_ole-snippets-shared-0.3.2 lib/ass_ole/snippets/shared/mapped.rb
ass_ole-snippets-shared-0.3.1 lib/ass_ole/snippets/shared/mapped.rb