Class: Pubid::Ieee::Components::Draft

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/ieee/components/draft.rb

Overview

IEEE draft version Handles formats like:

/D5              - version only
/D3.4            - version with revision
/D7, July 2019   - with date

Constant Summary collapse

MONTH_NAMES =

Month name to number mapping

{
  "January" => "1", "February" => "2", "March" => "3", "April" => "4",
  "May" => "5", "June" => "6", "July" => "7", "August" => "8",
  "September" => "9", "October" => "10", "November" => "11", "December" => "12",
  "Jan" => "1", "Feb" => "2", "Mar" => "3", "Apr" => "4",
  "Jun" => "6", "Jul" => "7", "Aug" => "8", "Sep" => "9", "Sept" => "9",
  "Oct" => "10", "Nov" => "11", "Dec" => "12"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version: nil, revision: nil, year: nil, month: nil, day: nil) ⇒ Draft

Returns a new instance of Draft.



34
35
36
37
38
39
40
41
42
43
# File 'lib/pubid/ieee/components/draft.rb', line 34

def initialize(version: nil, revision: nil, year: nil, month: nil,
day: nil)
  super()
  self.version = version
  self.revision = revision
  self.year = year
  self.original_month = month # Store original format
  self.month = convert_month(month)
  self.day = day
end

Class Method Details

.parse(value) ⇒ Draft

Parse a rendered draft such as "/D3", "/D3.4", "/D7 Jul 2019", or a bare "D5"/"5" back into a Draft. This is the exact inverse of #to_s: Draft.parse(d.to_s).to_s == d.to_s must hold, because the identifier stores the draft as its rendered string and rebuilds the object with this method after from_hash (a mismatch breaks to_hash round-trip).

Parameters:

  • value (String, Draft)

    the value to coerce

Returns:



64
65
66
67
68
69
70
71
72
# File 'lib/pubid/ieee/components/draft.rb', line 64

def self.parse(value)
  return value if value.is_a?(Draft)

  body = strip_prefix(value.to_s)
  version, month, day, year, comma = split_date(body)
  draft = new(version: version, month: month, day: day, year: year)
  draft.comma_before_month = comma
  draft
end

Instance Method Details

#convert_month(month_name) ⇒ Object

Convert month name to numeric value



100
101
102
103
104
# File 'lib/pubid/ieee/components/draft.rb', line 100

def convert_month(month_name)
  return nil unless month_name

  MONTH_NAMES[month_name] || month_name
end

#numeric_monthObject

Access the numeric month value



107
108
109
# File 'lib/pubid/ieee/components/draft.rb', line 107

def numeric_month
  month
end

#to_sObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/pubid/ieee/components/draft.rb', line 111

def to_s
  result = "/D#{version}"
  result += ".#{revision}" if revision

  if year
    # Use original month format to preserve abbreviated vs full names
    display_month = original_month

    if display_month
      # Use comma_before_month flag if set, otherwise detect from month format
      use_comma_before = if defined?(@comma_before_month) && !@comma_before_month.nil?
                           @comma_before_month
                         else
                           # Default: Full month names have comma, abbreviated don't
                           display_month.length > 4 && display_month != "Sept"
                         end

      result += use_comma_before ? ", #{display_month}" : " #{display_month}"
      result += " #{day}" if day

      # Abbreviated months: " Year", Full months: ", Year"
      result += if display_month.length <= 4 || display_month == "Sept"
                  " #{year}"
                else
                  ", #{year}"
                end
    else
      result += " #{year}"
    end
  end

  result
end