Class: Locabulary::Items::Base

Inherits:
Object
  • Object
show all
Extended by:
Dry::Configurable
Includes:
Comparable
Defined in:
lib/locabulary/items/base.rb

Overview

A singular item in the controlled vocubulary.

Direct Known Subclasses

AdministrativeUnit

Constant Summary collapse

HIERARCHY_DELIMITER =

Since:

  • 0.5.0

'::'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.

Since:

  • 0.5.0



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_onObject (readonly)

Date

When was this particular item activated

Since:

  • 0.5.0



35
36
37
# File 'lib/locabulary/items/base.rb', line 35

def activated_on
  @activated_on
end

#deactivated_onObject (readonly)

Date

When was this particular item deactivated

Since:

  • 0.5.0



38
39
40
# File 'lib/locabulary/items/base.rb', line 38

def deactivated_on
  @deactivated_on
end

#default_presentation_sequenceObject

Integer, nil

What is the order in which

See Also:

  • for details on how this is calculated

Since:

  • 0.5.0



42
43
44
# File 'lib/locabulary/items/base.rb', line 42

def default_presentation_sequence
  @default_presentation_sequence
end

#deposit_labelObject (readonly)

Deprecated.

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).

Since:

  • 0.5.0



47
48
49
# File 'lib/locabulary/items/base.rb', line 47

def deposit_label
  @deposit_label
end

#descriptionObject (readonly)

String

a side-car of more exhaustive information related to this particular term

Since:

  • 0.5.0



32
33
34
# File 'lib/locabulary/items/base.rb', line 32

def description
  @description
end

#predicate_nameObject

String

the trait for a given subject that we are describing by way of the term_label/term_uri

Since:

  • 0.5.0



19
20
21
# File 'lib/locabulary/items/base.rb', line 19

def predicate_name
  @predicate_name
end

#term_labelObject (readonly)

Note:

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

Since:

  • 0.5.0



24
25
26
# File 'lib/locabulary/items/base.rb', line 24

def term_label
  @term_label
end

#term_uriObject (readonly)

Note:

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

Since:

  • 0.5.0



29
30
31
# File 'lib/locabulary/items/base.rb', line 29

def term_uri
  @term_uri
end

Class Method Details

.hierarchy_delimiterObject

Since:

  • 0.5.0



122
123
124
# File 'lib/locabulary/items/base.rb', line 122

def self.hierarchy_delimiter
  HIERARCHY_DELIMITER
end

Instance Method Details

#<=>(other) ⇒ Object

Since:

  • 0.5.0



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.

Since:

  • 0.5.0



110
111
112
# File 'lib/locabulary/items/base.rb', line 110

def add_child(*input)
  @children += input
end

#attribute_namesObject

Since:

  • 0.5.0



14
15
16
# File 'lib/locabulary/items/base.rb', line 14

def attribute_names
  self.class.config.attribute_names
end

#childrenObject

Since:

  • 0.5.0



104
105
106
# File 'lib/locabulary/items/base.rb', line 104

def children
  @children.sort
end

#hierarchy_facet_labelObject

When rendered as part of a facet list

Since:

  • 0.5.0



156
157
158
# File 'lib/locabulary/items/base.rb', line 156

def hierarchy_facet_label
  slugs[-1]
end

#parent_slugsObject

Since:

  • 0.5.0



127
128
129
# File 'lib/locabulary/items/base.rb', line 127

def parent_slugs
  slugs[0..-2]
end

#parent_term_labelObject

Since:

  • 0.5.0



132
133
134
# File 'lib/locabulary/items/base.rb', line 132

def parent_term_label
  parent_slugs.join(HIERARCHY_DELIMITER)
end

#presentation_sequenceObject

Since:

  • 0.5.0



99
100
101
# File 'lib/locabulary/items/base.rb', line 99

def presentation_sequence
  default_presentation_sequence || SORT_SEQUENCE_FOR_NIL
end

#root_slugObject

Since:

  • 0.5.0



137
138
139
# File 'lib/locabulary/items/base.rb', line 137

def root_slug
  slugs[0]
end

#selectable?Boolean

Returns:

  • (Boolean)

Since:

  • 0.5.0



142
143
144
# File 'lib/locabulary/items/base.rb', line 142

def selectable?
  children.count.zero?
end

#selectable_labelObject

When rendered as part of a select list

Since:

  • 0.5.0



148
149
150
# File 'lib/locabulary/items/base.rb', line 148

def selectable_label
  slugs[-1]
end

#slugsObject

Since:

  • 0.5.0



117
118
119
# File 'lib/locabulary/items/base.rb', line 117

def slugs
  term_label.split(HIERARCHY_DELIMITER)
end

#to_hObject 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.

Since:

  • 0.5.0



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_fedoraObject Also known as: id

Since:

  • 0.5.0



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