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



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_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

#affiliationObject (readonly)

Deprecated.

Since:

  • 0.5.0



51
52
53
# File 'lib/locabulary/items/base.rb', line 51

def affiliation
  @affiliation
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.

Since:

  • 0.5.0



45
46
47
# File 'lib/locabulary/items/base.rb', line 45

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

#groupingObject (readonly)

Deprecated.

Since:

  • 0.5.0



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

def grouping
  @grouping
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



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

def self.hierarchy_delimiter
  HIERARCHY_DELIMITER
end

Instance Method Details

#<=>(other) ⇒ Object

Since:

  • 0.5.0



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.

Since:

  • 0.5.0



114
115
116
# File 'lib/locabulary/items/base.rb', line 114

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



108
109
110
# File 'lib/locabulary/items/base.rb', line 108

def children
  @children.sort
end

#hierarchy_facet_labelObject

When rendered as part of a facet list

Since:

  • 0.5.0



160
161
162
# File 'lib/locabulary/items/base.rb', line 160

def hierarchy_facet_label
  slugs[-1]
end

#parent_slugsObject

Since:

  • 0.5.0



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

def parent_slugs
  slugs[0..-2]
end

#parent_term_labelObject

Since:

  • 0.5.0



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

def parent_term_label
  parent_slugs.join(HIERARCHY_DELIMITER)
end

#presentation_sequenceObject

Since:

  • 0.5.0



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

def presentation_sequence
  default_presentation_sequence || SORT_SEQUENCE_FOR_NIL
end

#root_slugObject

Since:

  • 0.5.0



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

def root_slug
  slugs[0]
end

#selectable?Boolean

Returns:

  • (Boolean)

Since:

  • 0.5.0



146
147
148
# File 'lib/locabulary/items/base.rb', line 146

def selectable?
  children.count.zero?
end

#selectable_labelObject

When rendered as part of a select list

Since:

  • 0.5.0



152
153
154
# File 'lib/locabulary/items/base.rb', line 152

def selectable_label
  slugs[-1]
end

#slugsObject

Since:

  • 0.5.0



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

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



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

Since:

  • 0.5.0



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