Class: HashString
- Inherits:
-
Object
- Object
- HashString
- Defined in:
- lib/generators/ruby_rabbitmq_janus/create_request_generator.rb
Overview
Create an hash with an array
Instance Method Summary collapse
-
#convert_in_hash ⇒ Object
Create and return an hash.
-
#format_hash_string ⇒ Object
private
Transform string to hash.
-
#initialize(string_array) ⇒ HashString
constructor
Initialize an array.
-
#test_string_hash ⇒ Object
private
Test if string is hash.
-
#value ⇒ Object
private
Return the value for hash object.
Constructor Details
#initialize(string_array) ⇒ HashString
Initialize an array
23 24 25 26 |
# File 'lib/generators/ruby_rabbitmq_janus/create_request_generator.rb', line 23 def initialize(string_array) @array = string_array @hash = {} end |
Instance Method Details
#convert_in_hash ⇒ Object
Create and return an hash
29 30 31 32 |
# File 'lib/generators/ruby_rabbitmq_janus/create_request_generator.rb', line 29 def convert_in_hash @hash[@array[0]] = test_string_hash @hash end |
#format_hash_string ⇒ Object (private)
Transform string to hash
42 43 44 |
# File 'lib/generators/ruby_rabbitmq_janus/create_request_generator.rb', line 42 def format_hash_string @array.drop(1).join(':').sub('{', '').sub('}', '').split(String::SEPARATOR_KEY_VALUE) end |
#test_string_hash ⇒ Object (private)
Test if string is hash
37 38 39 |
# File 'lib/generators/ruby_rabbitmq_janus/create_request_generator.rb', line 37 def test_string_hash value.include?('{') ? HashString.new(format_hash_string).convert_in_hash : value end |
#value ⇒ Object (private)
Return the value for hash object
47 48 49 |
# File 'lib/generators/ruby_rabbitmq_janus/create_request_generator.rb', line 47 def value @array[1] end |