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 draft string like “D5”, “D3.4”, or “5” into a Draft object.

Parameters:

  • value (String, Draft)

    the value to coerce

Returns:



48
49
50
51
52
53
54
55
56
57
# File 'lib/pubid/ieee/components/draft.rb', line 48

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

  str = value.to_s
  if str =~ /^D(\d+)(?:\.(\d+))?/
    new(version: $1, revision: $2)
  else
    new(version: str)
  end
end

Instance Method Details

#convert_month(month_name) ⇒ Object

Convert month name to numeric value



60
61
62
63
64
# File 'lib/pubid/ieee/components/draft.rb', line 60

def convert_month(month_name)
  return nil unless month_name

  MONTH_NAMES[month_name] || month_name
end

#numeric_monthObject

Access the numeric month value



67
68
69
# File 'lib/pubid/ieee/components/draft.rb', line 67

def numeric_month
  month
end

#to_sObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/pubid/ieee/components/draft.rb', line 71

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