Class: RelatonBib::Series

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/series.rb

Overview

Series class.

Constant Summary collapse

TYPES =
%w[main alt].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Series

Returns a new instance of Series.

Parameters:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/relaton_bib/series.rb', line 67

def initialize(**args)
  unless args[:title].is_a?(RelatonBib::TypedTitleString) || args[:formattedref]
    raise ArgumentError, "argument `title` or `formattedref` should present"
  end

  if args[:type] && !TYPES.include?(args[:type])
    raise ArgumentError, "invalid argument `type`"
  end

  @type         = args[:type] # if %w[main alt].include? args[:type]
  @title        = args[:title]
  @formattedref = args[:formattedref]
  @place        = args[:place]
  @organization = args[:organization]
  @abbreviation = args[:abbreviation]
  @from         = args[:from]
  @to           = args[:to]
  @number       = args[:number]
  @partnumber  = args[:partnumber]
end

Instance Attribute Details

#abbreviationRelatonBib::LocalizedString, NilClass (readonly)

Returns:



41
42
43
# File 'lib/relaton_bib/series.rb', line 41

def abbreviation
  @abbreviation
end

#formattedrefRelatonBib::FormattedRef, NilClass (readonly)

Returns:



29
30
31
# File 'lib/relaton_bib/series.rb', line 29

def formattedref
  @formattedref
end

#fromString, NilClass (readonly)

Returns date or year.

Returns:

  • (String, NilClass)

    date or year



44
45
46
# File 'lib/relaton_bib/series.rb', line 44

def from
  @from
end

#numberString, NilClass (readonly)

Returns:

  • (String, NilClass)


50
51
52
# File 'lib/relaton_bib/series.rb', line 50

def number
  @number
end

#organizationString, NilClass (readonly)

Returns:

  • (String, NilClass)


38
39
40
# File 'lib/relaton_bib/series.rb', line 38

def organization
  @organization
end

#partnumberString, NilClass (readonly)

Returns:

  • (String, NilClass)


53
54
55
# File 'lib/relaton_bib/series.rb', line 53

def partnumber
  @partnumber
end

#placeString, NilClass (readonly)

Returns:

  • (String, NilClass)


35
36
37
# File 'lib/relaton_bib/series.rb', line 35

def place
  @place
end

#titleRelatonBib::FormattedString, NilClass (readonly)

Returns title.

Returns:



32
33
34
# File 'lib/relaton_bib/series.rb', line 32

def title
  @title
end

#toString, NilClass (readonly)

Returns date or year.

Returns:

  • (String, NilClass)

    date or year



47
48
49
# File 'lib/relaton_bib/series.rb', line 47

def to
  @to
end

#typeString, NilClass (readonly)

Returns allowed values: “main” or “alt”.

Returns:

  • (String, NilClass)

    allowed values: “main” or “alt”



26
27
28
# File 'lib/relaton_bib/series.rb', line 26

def type
  @type
end

Instance Method Details

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/relaton_bib/series.rb', line 92

def to_xml(builder)
  xml = builder.series do
    if formattedref
      formattedref.to_xml builder
    else
      builder.title { title.to_xml builder }
      builder.place place if place
      builder.organization organization if organization
      builder.abbreviation { abbreviation.to_xml builder } if abbreviation
      builder.from from if from
      builder.to to if to
      builder.number number if number
      builder.partnumber partnumber if partnumber
    end
  end
  xml[:type] = type if type
end