Class: Slimmer::Artefact
- Inherits:
-
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
42
43
44
45
46
|
# File 'lib/slimmer/artefact.rb', line 42
def method_missing(name, *args)
value = @data[name.to_s]
value ||= @data["details"][name.to_s] if @data["details"]
value
end
|
Instance Method Details
#legacy_sources ⇒ Object
29
30
31
32
33
|
# File 'lib/slimmer/artefact.rb', line 29
def legacy_sources
tags_of_type('legacy_source').map do |t|
id_to_slug(t["id"])
end
end
|
#primary_root_section ⇒ Object
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_section ⇒ Object
17
18
19
|
# File 'lib/slimmer/artefact.rb', line 17
def primary_section
tags_of_type("section").first
end
|
35
36
37
38
39
40
|
# File 'lib/slimmer/artefact.rb', line 35
def related_artefacts
return [] unless self.related
self.related.map do |r|
self.class.new(r)
end
end
|
#slug ⇒ Object
6
7
8
|
# File 'lib/slimmer/artefact.rb', line 6
def slug
id_to_slug(@data["id"])
end
|
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
|