class Onoma::PropertyNature

Attributes

default[RW]
fallbacks[RW]
name[RW]
nomenclature[R]
source[RW]
type[RW]

Public Class Methods

new(nomenclature, name, type, options = {}) click to toggle source

New item

# File lib/onoma/property_nature.rb, line 7
def initialize(nomenclature, name, type, options = {})
  @nomenclature = nomenclature
  @name = name.to_sym
  @type = type
  raise "Invalid type: #{@type.inspect}" unless Onoma::PROPERTY_TYPES.include?(@type)

  @fallbacks = options[:fallbacks] if options[:fallbacks]
  @default = options[:default] if options[:default]
  @required = !!options[:required]
  @source = options[:choices] if reference? && options[:choices]
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/onoma/property_nature.rb, line 93
def <=>(other)
  name <=> other.name
end
choices() click to toggle source

Returns list of choices for a given property

# File lib/onoma/property_nature.rb, line 68
def choices
  if inline_choices?
    @source || []
  elsif item_reference?
    @nomenclature.sibling(@source).all.map(&:to_sym)
  end
end
choices_nomenclature() click to toggle source
# File lib/onoma/property_nature.rb, line 63
def choices_nomenclature
  @source
end
human_name() click to toggle source

Return human name of property

# File lib/onoma/property_nature.rb, line 87
def human_name
  I18n.t("nomenclatures.#{nomenclature.name}.property_natures.#{name}", default: ["nomenclatures.#{nomenclature.name}.properties.#{name}".to_sym, "properties.#{name}".to_sym, "enumerize.#{nomenclature.name}.#{name}".to_sym, "labels.#{name}".to_sym, name.humanize])
end
Also aliased as: humanize
humanize()
Alias for: human_name
inline_choices?() click to toggle source
# File lib/onoma/property_nature.rb, line 47
def inline_choices?
  choice? || choice_list?
end
item_reference?() click to toggle source
# File lib/onoma/property_nature.rb, line 51
def item_reference?
  item? || item_list?
end
list?() click to toggle source
# File lib/onoma/property_nature.rb, line 59
def list?
  choice_list? || item_list? || string_list?
end
reference?() click to toggle source
# File lib/onoma/property_nature.rb, line 55
def reference?
  choice_list? || item_list? || string_list? || choice? || item?
end
required?() click to toggle source

Returns if property is required

# File lib/onoma/property_nature.rb, line 43
def required?
  @required
end
selection() click to toggle source
# File lib/onoma/property_nature.rb, line 76
def selection
  if inline_choices?
    choices.collect do |c|
      ["nomenclatures.#{@nomenclature.name}.choices.#{name}.#{c}".t, c]
    end
  elsif item_reference?
    @nomenclature.sibling(@source).selection
  end
end
to_xml_attrs() click to toggle source
# File lib/onoma/property_nature.rb, line 25
def to_xml_attrs
  attrs = {}
  attrs[:name] = @name.to_s
  attrs[:type] = @type.to_s
  if @source
    attrs[:choices] = if inline_choices?
                        @source.join(', ')
                      else
                        @source.to_s
                      end
  end
  attrs[:required] = 'true' if @required
  attrs[:fallbacks] = @fallbacks.join(', ') if @fallbacks
  attrs[:default] = @default.to_s if @default
  attrs
end