Class: Pubid::Asme::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/asme/builder.rb

Instance Method Summary collapse

Instance Method Details

#build(parsed_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pubid/asme/builder.rb', line 6

def build(parsed_hash)
  identifier = Identifiers::Standard.new

  # Handle joint publishers
  if parsed_hash[:joint_publisher]
    identifier.joint_publisher = parsed_hash[:joint_publisher].to_s
    identifier.publisher = parsed_hash[:joint_publisher].to_s
  elsif parsed_hash[:first_publisher]
    # CSA/ASME or API/ASME format
    identifier.first_publisher = parsed_hash[:first_publisher].to_s
    identifier.first_code = parsed_hash[:first_code].to_s
    identifier.second_publisher = parsed_hash[:second_publisher].to_s
    identifier.publisher = "#{parsed_hash[:first_publisher]}/#{parsed_hash[:second_publisher]}"
  else
    # Standard ASME
    identifier.publisher = "ASME"
  end

  # Build code component
  if parsed_hash[:designator]
    identifier.code = build_code(parsed_hash)
  end

  # Set PTC suffix
  if parsed_hash[:ptc_suffix]
    identifier.ptc_suffix = parsed_hash[:ptc_suffix].to_s
  end

  # Set year
  if parsed_hash[:year]
    identifier.year = parsed_hash[:year].to_s
  end

  # Set draft year
  if parsed_hash[:draft_year]
    identifier.draft_year = parsed_hash[:draft_year].to_s
  end

  # Set reaffirmation
  if parsed_hash[:reaffirmation]
    identifier.reaffirmation = "R#{parsed_hash[:reaffirmation]}"
  end

  # Set language (including lang_suffix from BPVC)
  if parsed_hash[:language]
    identifier.language = parsed_hash[:language].to_s
  elsif parsed_hash[:lang_suffix]
    identifier.language = parsed_hash[:lang_suffix].to_s
  end

  # Set CSA number (for ASME/CSA format)
  if parsed_hash[:csa_number]
    identifier.csa_number = parsed_hash[:csa_number].to_s
  end

  # Set handbook flag
  if parsed_hash[:handbook]
    identifier.handbook = true
  end

  # Set revision note
  if parsed_hash[:revision_note]
    identifier.revision_note = "[#{parsed_hash[:revision_note]}]"
  end

  # Set parenthetical revision
  if parsed_hash[:ref_standard]
    # Extract the type of revision (Revision/Proposed revision)
    ref = parsed_hash[:ref_standard].to_s
    if parsed_hash[:ref_standard].to_s =~ /^(Proposed revision|Revision) of (.+)$/
      identifier.parenthetical_revision = "(#{$1} of #{$2})"
    else
      identifier.parenthetical_revision = "(Revision of #{ref})"
    end
  end

  identifier
end