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

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

Instance Method Details

#convert_month(month_name) ⇒ Object

Convert month name to numeric value



46
47
48
49
50
# File 'lib/pubid/ieee/components/draft.rb', line 46

def convert_month(month_name)
  return nil unless month_name

  MONTH_NAMES[month_name] || month_name
end

#numeric_monthObject

Access the numeric month value



53
54
55
# File 'lib/pubid/ieee/components/draft.rb', line 53

def numeric_month
  month
end

#to_sObject



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
84
85
86
87
88
89
# File 'lib/pubid/ieee/components/draft.rb', line 57

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