Class: Pubid::Jcgm::Builder
Instance Attribute Summary
#identifier
Instance Method Summary
collapse
#initialize
Instance Method Details
#build(parsed_hash) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/pubid/jcgm/builder.rb', line 27
def build(parsed_hash)
klass = locate_identifier_klass(parsed_hash)
if parsed_hash[:gum_number] && klass == Identifiers::GumGuide
parsed_hash = parsed_hash.merge(number: parsed_hash[:gum_number])
parsed_hash.delete(:gum_number)
end
identifier = klass.new
assign_attributes(identifier, parsed_hash)
if identifier.class.attributes.key?(:typed_stage) && identifier.typed_stage.nil?
identifier.typed_stage = identifier.class.published_typed_stage ||
raise(ArgumentError, "No published typed_stage for #{identifier.class}")
end
identifier
end
|
#locate_identifier_klass(parsed_hash) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/pubid/jcgm/builder.rb', line 6
def locate_identifier_klass(parsed_hash)
if parsed_hash[:base]
type_with_stage = parsed_hash[:type_with_stage]
return Jcgm.locate_type(:amendment) unless type_with_stage
return Jcgm.locate_type(locate_typed_stage(type_with_stage).type_code)
end
if parsed_hash[:gum_number]
return Jcgm.locate_type(:gum_guide)
end
return Jcgm.locate_type(:guide) unless parsed_hash[:type_with_stage]
typed_stage = locate_typed_stage(parsed_hash[:type_with_stage])
Jcgm.locate_type(typed_stage.type_code)
end
|