class Parse::Conf::GitosisStyle

Constants

Helper

Attributes

config_raw[R]
data[R]
empty_group_name[R]

Public Class Methods

new(config_raw, separator = " ") click to toggle source
# File lib/parse/conf/gitosis_style.rb, line 8
def initialize(config_raw, separator = " ")
  @config_raw = config_raw
  @data = {}

  @empty_group_name = 'without_group'
  @separator = separator
  @data[empty_group_name] = []
end
run(config_raw, separator = " ") click to toggle source
# File lib/parse/conf/gitosis_style.rb, line 22
def self.run(config_raw, separator = " ")
  obj = new(config_raw, separator)
  obj.result
end

Public Instance Methods

result() click to toggle source
# File lib/parse/conf/gitosis_style.rb, line 17
def result
  parse unless @parsed
  @data
end

Private Instance Methods

build_line_insert_entity(line) click to toggle source
# File lib/parse/conf/gitosis_style.rb, line 45
def build_line_insert_entity(line)
  item = line.split('=').map{ |it| Helper.trim_and_remove_ugly_symbol(it) }
  Hash[*[item[0], item[1].split(@separator)]]
end
parse() click to toggle source
# File lib/parse/conf/gitosis_style.rb, line 28
def parse
  @parsed = true

  group_name = nil
  config_raw.lines.each do |line|
    next if line == "\n" || line =~ /^\#.*/

    if line =~ /\[.*\]/i
      group_name = Helper.trim_and_remove_ugly_symbol(line)
      data[group_name] = {}
    else
      insert_key = group_name ? group_name : empty_group_name
      data[insert_key].merge! (build_line_insert_entity(line))
    end
  end
end