Class: RelatonUn::Session

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_un/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Session

Returns a new instance of Session.

Parameters:

  • session_number (String)
  • session_date (String)
  • item_number (Array<String>)
  • collaborator (String)
  • agenda_id (String)
  • item_footnote (String)


22
23
24
25
26
27
28
29
30
31
# File 'lib/relaton_un/session.rb', line 22

def initialize(**args)
  @session_number = args[:session_number]
  @session_date = Date.parse args[:session_date] if args[:session_date]
  @item_number = args.fetch(:item_number, [])
  @item_name = args.fetch(:item_name, [])
  @subitem_name = args.fetch(:subitem_name, [])
  @collaborator = args[:collaborator]
  @agenda_id = args[:agenda_id]
  @item_footnote = args[:item_footnote]
end

Instance Attribute Details

#agenda_idString, NilClass (readonly)

Returns:

  • (String, NilClass)


6
7
8
# File 'lib/relaton_un/session.rb', line 6

def agenda_id
  @agenda_id
end

#collaboratorString, NilClass (readonly)

Returns:

  • (String, NilClass)


6
7
8
# File 'lib/relaton_un/session.rb', line 6

def collaborator
  @collaborator
end

#item_footnoteString, NilClass (readonly)

Returns:

  • (String, NilClass)


6
7
8
# File 'lib/relaton_un/session.rb', line 6

def item_footnote
  @item_footnote
end

#item_nameArray<String> (readonly)

Returns:

  • (Array<String>)


12
13
14
# File 'lib/relaton_un/session.rb', line 12

def item_name
  @item_name
end

#item_numberArray<String> (readonly)

Returns:

  • (Array<String>)


12
13
14
# File 'lib/relaton_un/session.rb', line 12

def item_number
  @item_number
end

#session_dateDate, NilClass (readonly)

Returns:

  • (Date, NilClass)


9
10
11
# File 'lib/relaton_un/session.rb', line 9

def session_date
  @session_date
end

#session_numberString, NilClass (readonly)

Returns:

  • (String, NilClass)


6
7
8
# File 'lib/relaton_un/session.rb', line 6

def session_number
  @session_number
end

#subitem_nameArray<String> (readonly)

Returns:

  • (Array<String>)


12
13
14
# File 'lib/relaton_un/session.rb', line 12

def subitem_name
  @subitem_name
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/relaton_un/session.rb', line 71

def to_asciibib(prefix = "")
  pref = prefix.empty? ? prefix : prefix + "."
  pref += "session"
  out = ""
  out += "#{pref}.session_number:: #{session_number}\n" if session_number
  out += "#{pref}.session_date:: #{session_date}\n" if session_date
  item_number.each { |n| out += "#{pref}.item_number:: #{n}\n" }
  item_name.each { |n| out += "#{pref}.item_name:: #{n}\n" }
  subitem_name.each { |n| out += "#{pref}.subitem_name:: #{n}\n" }
  out += "#{pref}.collaborator:: #{collaborator}\n" if collaborator
  out += "#{pref}.agenda_id:: #{agenda_id}\n" if agenda_id
  out += "#{pref}.item_footnote:: #{item_footnote}\n" if item_footnote
  out
end

#to_hashHash

rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength

Returns:

  • (Hash)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/relaton_un/session.rb', line 51

def to_hash
  hash = {}
  hash["session_number"] = session_number if session_number
  hash["session_date"] = session_date.to_s if session_date
  if item_number.any?
    hash["item_number"] = single_element_array(item_number)
  end
  hash["item_name"] = single_element_array(item_name) if item_name.any?
  if subitem_name.any?
    hash["subitem_name"] = single_element_array(subitem_name)
  end
  hash["collaborator"] = collaborator if collaborator
  hash["agenda_id"] = agenda_id if agenda_id
  hash["item_footnote"] = item_footnote if item_footnote
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • (Nokogiri::XML::Builder)


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/relaton_un/session.rb', line 36

def to_xml(builder)
  builder.session do |b|
    b.number session_number if session_number
    b.send "session-date", session_date.to_s if session_date
    item_number.each { |n| b.send "item-number", n }
    item_name.each { |n| b.send "item-name", n }
    subitem_name.each { |n| b.send "subitem-name", n }
    b.collaborator collaborator if collaborator
    b.send "agenda-id", agenda_id if agenda_id
    b.send "item-footnote", item_footnote if item_footnote
  end
end