Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DanRathbun opened this issue Apr 2, 2023 · 0 comments

Comments

@DanRathbun
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant