Class: LabelModel
- Inherits:
-
ASpaceExport::ExportModel
show all
- Defined in:
- backend/app/exporters/models/labels.rb
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
#apply_map, inherited, model_for, model_for?
#extract_date_string, #extract_note_content, #get_subnotes_by_type
Constructor Details
Returns a new instance of LabelModel
27
28
29
30
31
|
# File 'backend/app/exporters/models/labels.rb', line 27
def initialize(obj)
@json = obj
@rows = generate_label_rows(self.children)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(meth)
58
59
60
61
62
63
64
|
# File 'backend/app/exporters/models/labels.rb', line 58
def method_missing(meth)
if @json.respond_to?(meth)
@json.send(meth)
else
nil
end
end
|
Class Method Details
+ (Object) from_aspace_object(obj)
44
45
46
47
48
|
# File 'backend/app/exporters/models/labels.rb', line 44
def self.from_aspace_object(obj)
labler = self.new(obj)
labler
end
|
+ (Object) from_resource(obj)
51
52
53
54
55
|
# File 'backend/app/exporters/models/labels.rb', line 51
def self.from_resource(obj)
labler = self.from_aspace_object(obj)
labler
end
|
Instance Method Details
- (Object) children
82
83
84
85
86
87
88
89
90
|
# File 'backend/app/exporters/models/labels.rb', line 82
def children
return nil unless @json.tree.has_key?('_resolved') && @json.tree['_resolved']['children']
ao_class = self.class.instance_variable_get(:@ao)
children = @json.tree['_resolved']['children'].map { |subtree| ao_class.new(subtree) }
children
end
|
- (Object) generate_label_rows(objects)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'backend/app/exporters/models/labels.rb', line 93
def generate_label_rows(objects)
rows = []
objects.each do |obj|
instances = obj.instances
instances.each do |i|
c = i['container']
next unless c
crow = []
if c['type_1'] && c['indicator_1']
crow << "#{c['type_1']} #{c['indicator_1']}"
end
if c['barcode_1']
crow << c['barcode_1']
end
rows << crow
end
rows.push(*generate_label_rows(obj.children))
end
rows
end
|
34
35
36
|
# File 'backend/app/exporters/models/labels.rb', line 34
def
%w(Repository\ Name Resource\ Title Resource\ Identifier Container Label)
end
|
- (Object) identifier
66
67
68
69
70
|
# File 'backend/app/exporters/models/labels.rb', line 66
def identifier
@identifier ||= [:id_0, :id_1, :id_2, :id_3].map {|i| self.send(i) }.reject {|i| i.nil? }.join("-")
@identifier
end
|
- (Object) repo_name
73
74
75
76
77
78
79
|
# File 'backend/app/exporters/models/labels.rb', line 73
def repo_name
if self.repository && self.repository.has_key?('_resolved')
self.repository['_resolved']['name']
else
"Unknown"
end
end
|
- (Object) rows
39
40
41
|
# File 'backend/app/exporters/models/labels.rb', line 39
def rows
@rows.map {|r| [self.repo_name, self.title, self.identifier] + r }
end
|