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.
-
#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.
-
#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.
49 50 51 52 53 54 55 |
# File 'lib/locabulary/items/base.rb', line 49 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 |
#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)
The label to be used when depositing; This is deprecated in favor of mapping functions. Those mapping functions are in part described in Locabuarly (faceted_item_hierarchy_delimiter).
47 48 49 |
# File 'lib/locabulary/items/base.rb', line 47 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 |
#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
122 123 124 |
# File 'lib/locabulary/items/base.rb', line 122 def self.hierarchy_delimiter HIERARCHY_DELIMITER end |
Instance Method Details
#<=>(other) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/locabulary/items/base.rb', line 89 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.
110 111 112 |
# File 'lib/locabulary/items/base.rb', line 110 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
104 105 106 |
# File 'lib/locabulary/items/base.rb', line 104 def children @children.sort end |
#hierarchy_facet_label ⇒ Object
When rendered as part of a facet list
156 157 158 |
# File 'lib/locabulary/items/base.rb', line 156 def hierarchy_facet_label slugs[-1] end |
#parent_slugs ⇒ Object
127 128 129 |
# File 'lib/locabulary/items/base.rb', line 127 def parent_slugs slugs[0..-2] end |
#parent_term_label ⇒ Object
132 133 134 |
# File 'lib/locabulary/items/base.rb', line 132 def parent_term_label parent_slugs.join(HIERARCHY_DELIMITER) end |
#presentation_sequence ⇒ Object
99 100 101 |
# File 'lib/locabulary/items/base.rb', line 99 def presentation_sequence default_presentation_sequence || SORT_SEQUENCE_FOR_NIL end |
#root_slug ⇒ Object
137 138 139 |
# File 'lib/locabulary/items/base.rb', line 137 def root_slug slugs[0] end |
#selectable? ⇒ Boolean
142 143 144 |
# File 'lib/locabulary/items/base.rb', line 142 def selectable? children.count.zero? end |
#selectable_label ⇒ Object
When rendered as part of a select list
148 149 150 |
# File 'lib/locabulary/items/base.rb', line 148 def selectable_label slugs[-1] end |
#slugs ⇒ Object
117 118 119 |
# File 'lib/locabulary/items/base.rb', line 117 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.
58 59 60 61 62 63 |
# File 'lib/locabulary/items/base.rb', line 58 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
67 68 69 70 |
# File 'lib/locabulary/items/base.rb', line 67 def to_persistence_format_for_fedora return term_uri unless term_uri.to_s.strip == '' term_label end |