Class: RandomHex::RandomNumberTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- RandomHex::RandomNumberTag
- Defined in:
- random_hex.rb
Overview
Outputs a string of random hexadecimal characters of any length. Defaults to a six-character string.
Instance Method Summary collapse
-
#initialize(tag_name, text, context) ⇒ String?
constructor
Called by Jekyll only once to register the module.
-
#render(_) ⇒ Object
Constructor Details
#initialize(tag_name, text, context) ⇒ String?
Called by Jekyll only once to register the module.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'random_hex.rb', line 18 def initialize(tag_name, text, context) super#(tag_name, text, context) text.to_s.strip! if text.empty? @n = 6 else tokens = text.split(' ') abort "random_hex_string error - more than one token was provided: '#{text}'" if tokens.length > 1 not_integer = !Integer(text, exception: false) abort "random_hex_string error: '#{text}' is not a valid integer" if not_integer @n = text.to_i end end |
Instance Method Details
#render(_) ⇒ Object
32 33 34 35 |
# File 'random_hex.rb', line 32 def render(_) require 'securerandom' SecureRandom.hex(@n) end |