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