Class: Jekyll::GitHubMetadata::Value
- Inherits:
-
Object
- Object
- Jekyll::GitHubMetadata::Value
- Defined in:
- lib/jekyll-github-metadata/value.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Value
constructor
A new instance of Value.
- #render ⇒ Object
- #to_json ⇒ Object
- #to_liquid ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Value
Returns a new instance of Value.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jekyll-github-metadata/value.rb', line 8 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.new("#{args.size} args given but expected 1 or 2") end end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/jekyll-github-metadata/value.rb', line 6 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/jekyll-github-metadata/value.rb', line 6 def value @value end |
Instance Method Details
#render ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll-github-metadata/value.rb', line 21 def render @value = if @value.respond_to?(:call) case @value.arity when 0 @value.call when 1 @value.call(GitHubMetadata.client) when 2 @value.call(GitHubMetadata.client, GitHubMetadata.repository) else raise ArgumentError.new("Whoa, arity of 0, 1, or 2 please in your procs.") end else @value end @value = Sanitizer.sanitize(@value) rescue RuntimeError, NameError => e Jekyll::GitHubMetadata.log :error, "Error processing value '#{key}':" raise e end |
#to_json ⇒ Object
46 47 48 |
# File 'lib/jekyll-github-metadata/value.rb', line 46 def to_json(*) render.to_json end |
#to_liquid ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jekyll-github-metadata/value.rb', line 50 def to_liquid case render when nil nil when true, false value when Hash value when String, Numeric, Array value else to_json end end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/jekyll-github-metadata/value.rb', line 42 def to_s render.to_s end |