Class: RandomNumberTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- RandomNumberTag
- Defined in:
- lib/jekyll_random_hex.rb
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 'lib/jekyll_random_hex.rb', line 18 def initialize(tag_name, text, context) super 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 |
# File 'lib/jekyll_random_hex.rb', line 32 def render(_) SecureRandom.hex(@n) end |