Class: Pubid::Nist::Edition

Inherits:
Core::Entity
  • Object
show all
Defined in:
lib/pubid/nist/edition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed: nil, year: nil, month: nil, day: nil, number: nil) ⇒ Edition

Returns a new instance of Edition.



5
6
7
8
9
10
11
# File 'lib/pubid/nist/edition.rb', line 5

def initialize(parsed: nil, year: nil, month: nil, day: nil, number: nil)
  @parsed = parsed
  @year = year
  @month = month
  @day = day
  @number = number
end

Instance Attribute Details

#dayObject

Returns the value of attribute day.



3
4
5
# File 'lib/pubid/nist/edition.rb', line 3

def day
  @day
end

#monthObject

Returns the value of attribute month.



3
4
5
# File 'lib/pubid/nist/edition.rb', line 3

def month
  @month
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/pubid/nist/edition.rb', line 3

def number
  @number
end

#parsedObject

Returns the value of attribute parsed.



3
4
5
# File 'lib/pubid/nist/edition.rb', line 3

def parsed
  @parsed
end

#yearObject

Returns the value of attribute year.



3
4
5
# File 'lib/pubid/nist/edition.rb', line 3

def year
  @year
end

Instance Method Details

#to_s(format: :short) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pubid/nist/edition.rb', line 13

def to_s(format: :short)

  if format == :long
    result = (@number && ["Edition #{@number}"]) || []
    if @day
      result << Date.new(@year, @month, @day).strftime("(%B %d, %Y)")
    elsif @month
      result << Date.new(@year, @month).strftime("(%B %Y)")
    elsif @year
      result << Date.new(@year).strftime("(%Y)")
    end
    result.join(" ")
  else
    result = (@number && [@number]) || []
    if @day
      result << Date.new(@year, @month, @day).strftime("%Y%m%d")
    elsif @month
      result << Date.new(@year, @month).strftime("%Y%m")
    elsif @year
      result << Date.new(@year).strftime("%Y")
    end
    result.join("-")
  end
end