Class: HashString

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/ruby_rabbitmq_janus/create_request_generator.rb

Overview

Create an hash with an array

Instance Method Summary collapse

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_hashObject

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_stringObject (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_hashObject (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

#valueObject (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