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

Returns a new instance of ICS.

Parameters:

  • code (String)
  • text (String, nil) (defaults to: nil)


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)

Returns:

  • (String)


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

def code
  @code
end

#textString? (readonly)

Returns:

  • (String, nil)


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

def text
  @text
end

Instance Method Details

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

Parameters:

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

    number of ics

Returns:

  • (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

Returns:

  • (Hash)


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

Parameters:

  • builder (Nokogiri::XML::Builder)


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