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



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

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



11
12
13
# File 'lib/jekyll-github-metadata/value.rb', line 11

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value



11
12
13
# File 'lib/jekyll-github-metadata/value.rb', line 11

def value
  @value
end

Instance Method Details

#renderObject



26
27
28
29
30
31
32
33
# File 'lib/jekyll-github-metadata/value.rb', line 26

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



35
36
37
38
39
40
41
42
# File 'lib/jekyll-github-metadata/value.rb', line 35

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