lib/onoma/nomenclature.rb
# Add an property to the nomenclature from an XML element
Add an property to the nomenclature from an XML element
Add an property to the nomenclature from an XML element
def harvest_property(element)
      name = element.attr('name').to_sym
      type = element.attr('type').to_sym
      options = {}
      if element.has_attribute?('fallbacks')
        options[:fallbacks] = element.attr('fallbacks').to_s.strip.split(/[[:space:]]*\,[[:space:]]*/).map(&:to_sym)
      end
      if element.has_attribute?('default')
        options[:default] = element.attr('default').to_sym
      end
      options[:required] = !!(element.attr('required').to_s != 'true')
      if type == :list
        type = element.has_attribute?('nomenclature') ? :item_list : :choice_list
      elsif type == :choice
        type = :item if element.has_attribute?('nomenclature')
      end
      if type == :choice || type == :choice_list
        if element.has_attribute?('choices')
          options[:choices] = element.attr('choices').to_s.strip.split(/[[:space:]]*\,[[:space:]]*/).map(&:to_sym)
        else
          type = :string_list
        end
      elsif type == :item || type == :item_list
        if element.has_attribute?('choices')
          options[:choices] = element.attr('choices').to_s.strip.to_sym
        elsif element.has_attribute?('nomenclature')
          options[:choices] = element.attr('nomenclature').to_s.strip.to_sym
        else
          raise MissingChoices, "[#{@name}] Property #{name} must have nomenclature as choices"
        end
      end
      unless Property::TYPES.include?(type)
        raise ArgumentError, "Property #{name} type is unknown: #{type.inspect}"
      end
      add_property(name, type, options)
    end
def harvest_property ( element ) name = element . attr ( 'name' ) . to_sym type = element . attr ( 'type' ) . to_sym options = { } if element . has_attribute? ( 'fallbacks' ) options [ :fallbacks ] = element . attr ( 'fallbacks' ) . to_s . strip . split ( / [[:space:]]* \, [[:space:]]* / ) . map ( & :to_sym ) end if element . has_attribute? ( 'default' ) options [ :default ] = element . attr ( 'default' ) . to_sym end options [ :required ] = ! ! ( element . attr ( 'required' ) . to_s != 'true' ) if type == :list type = element . has_attribute? ( 'nomenclature' ) ? :item_list : :choice_list elsif type == :choice type = :item if element . has_attribute? ( 'nomenclature' ) end if type == :choice || type == :choice_list if element . has_attribute? ( 'choices' ) options [ :choices ] = element . attr ( 'choices' ) . to_s . strip . split ( / [[:space:]]* \, [[:space:]]* / ) . map ( & :to_sym ) else type = :string_list end elsif type == :item || type == :item_list if element . has_attribute? ( 'choices' ) options [ :choices ] = element . attr ( 'choices' ) . to_s . strip . to_sym elsif element . has_attribute? ( 'nomenclature' ) options [ :choices ] = element . attr ( 'nomenclature' ) . to_s . strip . to_sym else raise MissingChoices , "[#{@name}] Property #{name} must have nomenclature as choices" end end unless Property :: TYPES . include? ( type ) raise ArgumentError , "Property #{name} type is unknown: #{type.inspect}" end add_property ( name , type , options ) end
Add an property to the nomenclature from an XML element
Add an property to the nomenclature from an XML element
# options[:inherit]  = !!(element.attr('inherit').to_s == 'true')
element
<not_specific>