Class: ConceptView

Inherits:
Object
  • Object
show all
Defined in:
app/view_models/concept_view.rb

Defined Under Namespace

Classes: Language, Link

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concept, h) ⇒ ConceptView

‘h` is the controller/helper context which acts as a proxy here



26
27
28
29
30
# File 'app/view_models/concept_view.rb', line 26

def initialize(concept, h)
  @h = h
  @concept = concept
  @published = @concept.published? ? nil : '0'
end

Instance Attribute Details

#alt_labelsObject (readonly)

Returns the value of attribute alt_labels.



3
4
5
# File 'app/view_models/concept_view.rb', line 3

def alt_labels
  @alt_labels
end

#languagesObject (readonly)

Returns the value of attribute languages.



2
3
4
# File 'app/view_models/concept_view.rb', line 2

def languages
  @languages
end

#pref_labelsObject (readonly)

Returns the value of attribute pref_labels.



3
4
5
# File 'app/view_models/concept_view.rb', line 3

def pref_labels
  @pref_labels
end

Instance Method Details

#collectionsObject

returns a list of ‘Link`s



59
60
61
62
63
# File 'app/view_models/concept_view.rb', line 59

def collections
  @collections ||= @concept.collections.map do |coll|
    Link.new(coll.label.to_s, h.collection_path(:id => coll))
  end
end

#definitionObject

returns a string



37
38
39
40
41
# File 'app/view_models/concept_view.rb', line 37

def definition
  @definition ||= @concept.notes_for_class(Note::SKOS::Definition)
    .first # FIXME: hard-coded class, arbitrary pick
    .try(:value)
end

#no_content?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/view_models/concept_view.rb', line 32

def no_content?
  definition.blank? && alt_labels.none? && related.none? && collections.none?
end

related concepts returns a list of ‘Link`s



49
50
51
52
53
54
55
56
# File 'app/view_models/concept_view.rb', line 49

def related
  klass = Iqvoc::Concept.further_relation_classes.first # XXX: arbitrary; bad heuristic?
  @related = @concept.related_concepts_for_relation_class(klass, @published).
  map do |rel_concept|
    Link.new(rel_concept.pref_label.to_s,
    h.concept_path(:id => rel_concept))
  end
end