Class: Slimmer::Artefact

Inherits:
Object
  • Object
show all
Defined in:
lib/slimmer/artefact.rb

Instance Method Summary collapse

Constructor Details

#initialize(artefact_data) ⇒ Artefact

Returns a new instance of Artefact.



2
3
4
# File 'lib/slimmer/artefact.rb', line 2

def initialize(artefact_data)
  @data = artefact_data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



36
37
38
39
40
# File 'lib/slimmer/artefact.rb', line 36

def method_missing(name, *args)
  value = @data[name.to_s]
  value ||= @data["details"][name.to_s] if @data["details"]
  value
end

Instance Method Details

#primary_root_sectionObject



21
22
23
24
25
26
27
# File 'lib/slimmer/artefact.rb', line 21

def primary_root_section
  section = primary_section
  while section and section["parent"]
    section = section["parent"]
  end
  section
end

#primary_sectionObject



17
18
19
# File 'lib/slimmer/artefact.rb', line 17

def primary_section
  tags_of_type("section").first
end


29
30
31
32
33
34
# File 'lib/slimmer/artefact.rb', line 29

def related_artefacts
  return [] unless self.related
  self.related.map do |r|
    self.class.new(r)
  end
end

#slugObject



6
7
8
# File 'lib/slimmer/artefact.rb', line 6

def slug
  id_to_slug(@data["id"])
end

#tags_of_type(type) ⇒ Object



10
11
12
13
14
15
# File 'lib/slimmer/artefact.rb', line 10

def tags_of_type(type)
  return [] unless self.tags
  self.tags.select do |t|
    t["details"]["type"] == type
  end
end