Skip to content

FYI: Attribute_Dictionary has Enumerable#to_h that makes converting to Hash easy #1

@DanRathbun

Description

@DanRathbun

Attribute_Dictionary has Enumerable#to_h that makes converting to Hash easy

https://github.com/SketchUp/sketchup-annotations/blob/main/src/su_annotations/annotation_manager.rb

self.load(), at line 20 ...

    # @param [Sketchup::Page] page
    # @return [Hash]
    def self.load(page)
      return {} if page.nil?

      dictionary = page.attribute_dictionary(DICTIONARY_NAME, false)
      return {} if dictionary.nil?

      annotations = {}
      dictionary.each { |type, data|
        annotations[type.to_sym] = data
      }
      annotations
    end

... can be simplified to ...

    # @param [Sketchup::Page] page
    # @return [Hash]
    def self.load(page)
      return {} if page.nil?

      dictionary = page.attribute_dictionary(DICTIONARY_NAME, false)
      return {} if dictionary.nil?

      dictionary.to_h { |type, data| [ type.to_sym, data ] }
    end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions