Class: Onoma::PropertyNature
- Inherits:
-
Object
- Object
- Onoma::PropertyNature
- Defined in:
- lib/onoma/property_nature.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#fallbacks ⇒ Object
readonly
Returns the value of attribute fallbacks.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nomenclature ⇒ Object
readonly
Returns the value of attribute nomenclature.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#choices ⇒ Object
Returns list of choices for a given property.
- #choices_nomenclature ⇒ Object
-
#human_name ⇒ Object
(also: #humanize)
Return human name of property.
-
#initialize(nomenclature, name, type, options = {}) ⇒ PropertyNature
constructor
New item.
- #inline_choices? ⇒ Boolean
- #item_reference? ⇒ Boolean
- #list? ⇒ Boolean
- #reference? ⇒ Boolean
-
#required? ⇒ Boolean
Returns if property is required.
- #selection ⇒ Object
- #to_xml_attrs ⇒ Object
Constructor Details
#initialize(nomenclature, name, type, options = {}) ⇒ PropertyNature
New item
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/onoma/property_nature.rb', line 6 def initialize(nomenclature, name, type, = {}) @nomenclature = nomenclature @name = name.to_sym @type = type raise "Invalid type: #{@type.inspect}" unless Onoma::PROPERTY_TYPES.include?(@type) @fallbacks = [:fallbacks] if [:fallbacks] @default = [:default] if [:default] @required = !![:required] @source = [:choices] if reference? && [:choices] end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
3 4 5 |
# File 'lib/onoma/property_nature.rb', line 3 def default @default end |
#fallbacks ⇒ Object (readonly)
Returns the value of attribute fallbacks.
3 4 5 |
# File 'lib/onoma/property_nature.rb', line 3 def fallbacks @fallbacks end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/onoma/property_nature.rb', line 3 def name @name end |
#nomenclature ⇒ Object (readonly)
Returns the value of attribute nomenclature.
3 4 5 |
# File 'lib/onoma/property_nature.rb', line 3 def nomenclature @nomenclature end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/onoma/property_nature.rb', line 3 def source @source end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/onoma/property_nature.rb', line 3 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
92 93 94 |
# File 'lib/onoma/property_nature.rb', line 92 def <=>(other) name <=> other.name end |
#choices ⇒ Object
Returns list of choices for a given property
67 68 69 70 71 72 73 |
# File 'lib/onoma/property_nature.rb', line 67 def choices if inline_choices? @source || [] elsif item_reference? @nomenclature.sibling(@source).all.map(&:to_sym) end end |
#choices_nomenclature ⇒ Object
62 63 64 |
# File 'lib/onoma/property_nature.rb', line 62 def choices_nomenclature @source end |
#human_name ⇒ Object Also known as: humanize
Return human name of property
86 87 88 |
# File 'lib/onoma/property_nature.rb', line 86 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 |
#inline_choices? ⇒ Boolean
46 47 48 |
# File 'lib/onoma/property_nature.rb', line 46 def inline_choices? choice? || choice_list? end |
#item_reference? ⇒ Boolean
50 51 52 |
# File 'lib/onoma/property_nature.rb', line 50 def item_reference? item? || item_list? end |
#list? ⇒ Boolean
58 59 60 |
# File 'lib/onoma/property_nature.rb', line 58 def list? choice_list? || item_list? || string_list? end |
#reference? ⇒ Boolean
54 55 56 |
# File 'lib/onoma/property_nature.rb', line 54 def reference? choice_list? || item_list? || string_list? || choice? || item? end |
#required? ⇒ Boolean
Returns if property is required
42 43 44 |
# File 'lib/onoma/property_nature.rb', line 42 def required? @required end |
#selection ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/onoma/property_nature.rb', line 75 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 ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/onoma/property_nature.rb', line 24 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 |