Class: RelatonBib::Series

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

Overview

Series class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Series

Returns a new instance of Series.

Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/relaton_bib/series.rb', line 38

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

  # if args[:type] && !TYPES.include?(args[:type])
  #   warn "[relaton-bib] Series type is invalid: #{args[: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]
  @run          = args[:run]
end

Instance Attribute Details

#abbreviationRelatonBib::LocalizedString? (readonly)

Returns:



23
24
25
# File 'lib/relaton_bib/series.rb', line 23

def abbreviation
  @abbreviation
end

#formattedrefRelatonBib::FormattedRef? (readonly)

Returns:



14
15
16
# File 'lib/relaton_bib/series.rb', line 14

def formattedref
  @formattedref
end

#fromString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def from
  @from
end

#numberString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def number
  @number
end

#organizationString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def organization
  @organization
end

#partnumberString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def partnumber
  @partnumber
end

#placeString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def place
  @place
end

#runString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def run
  @run
end

#titleRelatonBib::TypedTitleString (readonly)

Returns title.

Returns:



17
18
19
# File 'lib/relaton_bib/series.rb', line 17

def title
  @title
end

#toString? (readonly)

Returns:

  • (String, nil)


20
21
22
# File 'lib/relaton_bib/series.rb', line 20

def to
  @to
end

#typeString? (readonly)

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

Returns:

  • (String, nil)

    allowed values: “main” or “alt”



11
12
13
# File 'lib/relaton_bib/series.rb', line 11

def type
  @type
end

Instance Method Details

#to_asciibib(prefix = "", count = 1) ⇒ String

Parameters:

  • prefix (String) (defaults to: "")
  • count (Integer) (defaults to: 1)

Returns:

  • (String)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/relaton_bib/series.rb', line 102

def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
  pref = prefix.empty? ? "series" : prefix + ".series"
  out = count > 1 ? "#{pref}::\n" : ""
  out += "#{pref}.type:: #{type}\n" if type
  out += formattedref.to_asciibib pref if formattedref
  out += title.to_asciibib pref
  out += "#{pref}.place:: #{place}\n" if place
  out += "#{pref}.organization:: #{organization}\n" if organization
  out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
  out += "#{pref}.from:: #{from}\n" if from
  out += "#{pref}.to:: #{to}\n" if to
  out += "#{pref}.number:: #{number}\n" if number
  out += "#{pref}.partnumber:: #{partnumber}\n" if partnumber
  out += "#{pref}.run:: #{run}\n" if run
  out
end

#to_hashHash

Returns:

  • (Hash)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/relaton_bib/series.rb', line 83

def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
  hash = {}
  hash["type"] = type if type
  hash["formattedref"] = formattedref.to_hash if formattedref
  hash["title"] = title.to_hash
  hash["place"] = place if place
  hash["organization"] = organization if organization
  hash["abbreviation"] = abbreviation.to_hash if abbreviation
  hash["from"] = from if from
  hash["to"] = to if to
  hash["number"] = number if number
  hash["partnumber"] = partnumber if partnumber
  hash["run"] = run if run
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/relaton_bib/series.rb', line 64

def to_xml(builder) # rubocop:disable Metrics/MethodLength
  xml = builder.series do
    formattedref&.to_xml builder
    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
    builder.run run if run
  end
  xml[:type] = type if type
end