Class: Locabulary::Items::Base
- Inherits:
-
Object
- Object
- Locabulary::Items::Base
- Extended by:
- Dry::Configurable
- Includes:
- Comparable
- Defined in:
- lib/locabulary/items/base.rb
Overview
A singular item in the controlled vocubulary.
Direct Known Subclasses
Constant Summary collapse
- HIERARCHY_DELIMITER =
'::'.freeze
Instance Attribute Summary collapse
-
#activated_on ⇒ Object
readonly
- Date
-
When was this particular item activated.
- #affiliation ⇒ Object readonly deprecated Deprecated.
-
#deactivated_on ⇒ Object
readonly
- Date
-
When was this particular item deactivated.
-
#default_presentation_sequence ⇒ Object
readonly
- Integer, nil
-
What is the order in which.
- #deposit_label ⇒ Object readonly deprecated Deprecated.
-
#description ⇒ Object
readonly
- String
-
a side-car of more exhaustive information related to this particular term.
- #grouping ⇒ Object readonly deprecated Deprecated.
-
#predicate_name ⇒ Object
readonly
- String
-
the trait for a given subject that we are describing by way of the term_label/term_uri.
-
#term_label ⇒ Object
readonly
- String
-
the human friendly version of the meaning for this given trait.
-
#term_uri ⇒ Object
readonly
- String
-
the machine friendly version of the meaning for this given trait.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#add_child(*input) ⇒ Object
private
Yes, this is private.
- #attribute_names ⇒ Object
- #children ⇒ Object
-
#hierarchy_facet_label ⇒ Object
When rendered as part of a facet list.
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #parent_slugs ⇒ Object
- #parent_term_label ⇒ Object
- #presentation_sequence ⇒ Object
- #root_slug ⇒ Object
- #selectable? ⇒ Boolean
-
#selectable_label ⇒ Object
When rendered as part of a select list.
- #slugs ⇒ Object
- #to_h ⇒ Object (also: #as_json) private
- #to_persistence_format_for_fedora ⇒ Object (also: #id)
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
53 54 55 56 57 58 59 |
# File 'lib/locabulary/items/base.rb', line 53 def initialize(attributes = {}) attribute_names.each do |key| value = attributes[key] || attributes[key.to_s] send("#{key}=", value) end @children = [] end |
Instance Attribute Details
#activated_on ⇒ Object (readonly)
- Date
-
When was this particular item activated
35 36 37 |
# File 'lib/locabulary/items/base.rb', line 35 def activated_on @activated_on end |
#affiliation ⇒ Object (readonly)
51 52 53 |
# File 'lib/locabulary/items/base.rb', line 51 def affiliation @affiliation end |
#deactivated_on ⇒ Object (readonly)
- Date
-
When was this particular item deactivated
38 39 40 |
# File 'lib/locabulary/items/base.rb', line 38 def deactivated_on @deactivated_on end |
#default_presentation_sequence ⇒ Object
- Integer, nil
-
What is the order in which
42 43 44 |
# File 'lib/locabulary/items/base.rb', line 42 def default_presentation_sequence @default_presentation_sequence end |
#deposit_label ⇒ Object (readonly)
45 46 47 |
# File 'lib/locabulary/items/base.rb', line 45 def deposit_label @deposit_label end |
#description ⇒ Object (readonly)
- String
-
a side-car of more exhaustive information related to this particular term
32 33 34 |
# File 'lib/locabulary/items/base.rb', line 32 def description @description end |
#grouping ⇒ Object (readonly)
48 49 50 |
# File 'lib/locabulary/items/base.rb', line 48 def grouping @grouping end |
#predicate_name ⇒ Object
- String
-
the trait for a given subject that we are describing by way of the term_label/term_uri
19 20 21 |
# File 'lib/locabulary/items/base.rb', line 19 def predicate_name @predicate_name end |
#term_label ⇒ Object (readonly)
For the time being, please regard the term_label as immutable; If you need a modification, deactivate this one and activate a new one
- String
-
the human friendly version of the meaning for this given trait
24 25 26 |
# File 'lib/locabulary/items/base.rb', line 24 def term_label @term_label end |
#term_uri ⇒ Object (readonly)
For the time being, please regard the term_uri as immutable; If you need a modification, deactivate this one and activate a new one
- String
-
the machine friendly version of the meaning for this given trait
29 30 31 |
# File 'lib/locabulary/items/base.rb', line 29 def term_uri @term_uri end |
Class Method Details
.hierarchy_delimiter ⇒ Object
126 127 128 |
# File 'lib/locabulary/items/base.rb', line 126 def self.hierarchy_delimiter HIERARCHY_DELIMITER end |
Instance Method Details
#<=>(other) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/locabulary/items/base.rb', line 93 def <=>(other) predicate_name_sort = predicate_name <=> other.predicate_name return predicate_name_sort unless predicate_name_sort.zero? presentation_sequence_sort = presentation_sequence <=> other.presentation_sequence return presentation_sequence_sort unless presentation_sequence_sort.zero? term_label <=> other.term_label end |
#add_child(*input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yes, this is private. Its an internal mechanism.
114 115 116 |
# File 'lib/locabulary/items/base.rb', line 114 def add_child(*input) @children += input end |
#attribute_names ⇒ Object
14 15 16 |
# File 'lib/locabulary/items/base.rb', line 14 def attribute_names self.class.config.attribute_names end |
#children ⇒ Object
108 109 110 |
# File 'lib/locabulary/items/base.rb', line 108 def children @children.sort end |
#hierarchy_facet_label ⇒ Object
When rendered as part of a facet list
160 161 162 |
# File 'lib/locabulary/items/base.rb', line 160 def hierarchy_facet_label slugs[-1] end |
#parent_slugs ⇒ Object
131 132 133 |
# File 'lib/locabulary/items/base.rb', line 131 def parent_slugs slugs[0..-2] end |
#parent_term_label ⇒ Object
136 137 138 |
# File 'lib/locabulary/items/base.rb', line 136 def parent_term_label parent_slugs.join(HIERARCHY_DELIMITER) end |
#presentation_sequence ⇒ Object
103 104 105 |
# File 'lib/locabulary/items/base.rb', line 103 def presentation_sequence default_presentation_sequence || SORT_SEQUENCE_FOR_NIL end |
#root_slug ⇒ Object
141 142 143 |
# File 'lib/locabulary/items/base.rb', line 141 def root_slug slugs[0] end |
#selectable? ⇒ Boolean
146 147 148 |
# File 'lib/locabulary/items/base.rb', line 146 def selectable? children.count.zero? end |
#selectable_label ⇒ Object
When rendered as part of a select list
152 153 154 |
# File 'lib/locabulary/items/base.rb', line 152 def selectable_label slugs[-1] end |
#slugs ⇒ Object
121 122 123 |
# File 'lib/locabulary/items/base.rb', line 121 def slugs term_label.split(HIERARCHY_DELIMITER) end |
#to_h ⇒ Object Also known as: as_json
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 |
# File 'lib/locabulary/items/base.rb', line 62 def to_h attribute_names.each_with_object({}) do |key, mem| mem[key.to_s] = send(key) unless send(key).to_s.strip == '' mem end end |
#to_persistence_format_for_fedora ⇒ Object Also known as: id
71 72 73 74 |
# File 'lib/locabulary/items/base.rb', line 71 def to_persistence_format_for_fedora return term_uri unless term_uri.to_s.strip == '' term_label end |