Class: RelatonBib::ICS

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, text: nil) ⇒ ICS



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

def initialize(code:, text: nil)
  @code = code
  @text = text
end

Instance Attribute Details

#codeString (readonly)



4
5
6
# File 'lib/relaton_bib/ics.rb', line 4

def code
  @code
end

#textString? (readonly)



7
8
9
# File 'lib/relaton_bib/ics.rb', line 7

def text
  @text
end

Instance Method Details

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



34
35
36
37
38
39
40
# File 'lib/relaton_bib/ics.rb', line 34

def to_asciibib(prefix = "", count = 1)
  pref = prefix.empty? ? "ics" : "#{prefix}.ics"
  out = count > 1 ? "#{pref}::\n" : ""
  out += "#{pref}.code:: #{code}\n"
  out += "#{pref}.text:: #{text}\n" if text
  out
end

#to_hashHash



25
26
27
28
29
# File 'lib/relaton_bib/ics.rb', line 25

def to_hash
  hash = { "code" => code }
  hash["text"] = text if text
  hash
end

#to_xml(builder) ⇒ Object



17
18
19
20
21
22
# File 'lib/relaton_bib/ics.rb', line 17

def to_xml(builder)
  builder.ics do |b|
    b.code code
    b.text_ text if text
  end
end