Class: Pubid::Ieee::Nesc::Builder

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

Overview

Builder for NESC identifier objects

Transforms parsed hash into appropriate NESC identifier class instances. Determines the correct identifier type based on parsed attributes and constructs the object with proper components.

Examples:

Build standard NESC

builder = Builder.new
parsed = { code: "C2", year: "1997" }
identifier = builder.build(parsed)
# => #<Pubid::Ieee::Identifiers::Nesc::Standard>

Build handbook

parsed = { year: "2017", variant: "Handbook", edition: "Premier Edition" }
identifier = builder.build(parsed)
# => #<Pubid::Ieee::Identifiers::Nesc::Handbook>

Instance Method Summary collapse

Instance Method Details

#build(parsed_hash) ⇒ Identifiers::Nesc::Base

Build NESC identifier from parsed hash

Parameters:

  • parsed_hash (Hash)

    Hash from parser

Returns:



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
# File 'lib/pubid/ieee/nesc/builder.rb', line 27

def build(parsed_hash)
  # Determine identifier type based on parsed attributes
  identifier_class = determine_identifier_class(parsed_hash)

  identifier = identifier_class.new

  # Set code if present (C2)
  if parsed_hash[:code]
    code_str = parsed_hash[:code].to_s
    identifier.code = Pubid::Ieee::Components::Code.new(
      prefix: code_str[0], # "C" from "C2"
      number: code_str[1..], # "2" from "C2"
    )
  end

  # Set year (required for all NESC identifiers)
  if parsed_hash[:year]
    identifier.year = Pubid::Components::Date.new(
      year: parsed_hash[:year].to_s.to_i,
    )
  end

  # Set variant (Handbook, Redline, etc.)
  if parsed_hash[:variant]
    identifier.variant = parsed_hash[:variant].to_s
  end

  # Set edition (for handbooks)
  if parsed_hash[:edition]
    identifier.edition = parsed_hash[:edition].to_s
  end

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

  # Set month (for drafts)
  if parsed_hash[:month]
    identifier.month = parsed_hash[:month].to_s
  end

  identifier
end