Class: MonkeyKing::SecretTag
- Inherits:
-
Object
- Object
- MonkeyKing::SecretTag
- Defined in:
- lib/monkey_king/parser.rb
Instance Attribute Summary collapse
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
- #gen_secret(length) ⇒ Object
- #init_with(coder) ⇒ Object
-
#initialize(*secret) ⇒ SecretTag
constructor
A new instance of SecretTag.
Constructor Details
#initialize(*secret) ⇒ SecretTag
Returns a new instance of SecretTag.
9 10 11 |
# File 'lib/monkey_king/parser.rb', line 9 def initialize( *secret ) self.secret = *secret end |
Instance Attribute Details
#secret ⇒ Object
Returns the value of attribute secret.
7 8 9 |
# File 'lib/monkey_king/parser.rb', line 7 def secret @secret end |
Instance Method Details
#encode_with(coder) ⇒ Object
22 23 24 25 |
# File 'lib/monkey_king/parser.rb', line 22 def encode_with( coder ) coder.style = Psych::Nodes::Mapping::FLOW coder.scalar = gen_secret(@secret.length) end |
#gen_secret(length) ⇒ Object
31 32 33 |
# File 'lib/monkey_king/parser.rb', line 31 def gen_secret(length) [*('a'..'z'),*('0'..'9'),*('A'..'Z')].shuffle[0,length].join end |
#init_with(coder) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/monkey_king/parser.rb', line 13 def init_with( coder ) case coder.type when :scalar self.secret = coder.scalar else raise "Dunno how to handle #{coder.type} for #{coder.inspect}" end end |