Module: Asciidoctor::NabeHelper

Included in:
PDF::Converter, Prawn::Outline
Defined in:
lib/asciidoctor/nabetani/nabehelper.rb

Class Method Summary collapse

Class Method Details

.get_node_attriute_float(node, name, fallback) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/asciidoctor/nabetani/nabehelper.rb', line 4

def get_node_attriute_float node, name, fallback
  t = node.attributes[name]
  return fallback unless t

  begin
    return Float(t)
  rescue ArgumentError => e
    raise ArgumentError, "#{name} value should be float value, but it is #{t.inspect} (#{e.inspect})"
  end
end

.get_node_attriute_float_array(node, name, fallback) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/asciidoctor/nabetani/nabehelper.rb', line 29

def get_node_attriute_float_array node, name, fallback
  t = node.attributes[name]
  return fallback unless t

  begin
    return t.split(",").map{ |e| Float(e.strip) }
  rescue ArgumentError => e
    raise ArgumentError, "#{name} value should be array of float value, but it is #{t.inspect} (#{e.inspect})"
  end
end

.three_state(v0, key) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asciidoctor/nabetani/nabehelper.rb', line 15

def three_state(v0, key)
  v = v0.is_a?(String) ? v0.downcase.strip : v0
  case v
  when true, 1, 'true', '1', 'yes', 'on'
    true
  when false, 0, 'false', '0', 'no', 'off'
    false
  when nil, 'nil', 'null', 'default', '~'
    nil
  else
    raise ArgumentError, "#{key} should be true, false, or nil, but it is #{v0.inspect}"
  end
end