Class: Jekyll::GitHubMetadata::Value

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jekyll-github-metadata/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Value

Returns a new instance of Value.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jekyll-github-metadata/value.rb', line 11

def initialize(*args)
  case args.size
  when 1
    @key = "{anonymous}"
    @value = args.first
  when 2
    @key = args.first.to_s
    @value = args.last
  else
    raise ArgumentError, "#{args.size} args given but expected 1 or 2"
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/jekyll-github-metadata/value.rb', line 9

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/jekyll-github-metadata/value.rb', line 9

def value
  @value
end

Instance Method Details

#renderObject



24
25
26
27
28
29
30
# File 'lib/jekyll-github-metadata/value.rb', line 24

def render
  return @rendered if defined? @rendered
  @rendered = @value = Sanitizer.sanitize(call_or_value)
rescue RuntimeError, NameError => e
  Jekyll::GitHubMetadata.log :error, "Error processing value '#{key}':"
  raise e
end

#to_liquidObject



32
33
34
35
36
37
38
39
# File 'lib/jekyll-github-metadata/value.rb', line 32

def to_liquid
  case render
  when nil, true, false, Hash, String, Numeric, Array
    value
  else
    to_json
  end
end