Module: CfScript::Output::Parser::Attributes

Included in:
CfScript::Output::Parser
Defined in:
lib/cf_script/output/parser/attributes.rb

Constant Summary collapse

ATTRIBUTE_REGEXP =
/^(?<name>[^:]+):\s+(?<value>.+)$/

Instance Method Summary collapse

Instance Method Details

#parse_attribute(line, symbolize_name = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cf_script/output/parser/attributes.rb', line 5

def parse_attribute(line, symbolize_name = false)
  if line =~ ATTRIBUTE_REGEXP
    name  = Regexp.last_match[:name].strip
    value = Regexp.last_match[:value].strip

    CfScript::Attribute.new(
      symbolize_name ? symbolize(name) : name,
      value
    )
  end
end

#parse_attribute_list(buffer, symbolize_names = true) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cf_script/output/parser/attributes.rb', line 17

def parse_attribute_list(buffer, symbolize_names = true)
  attribute_list = CfScript::AttributeList.new

  buffer.each_line do |line|
    if attribute = parse_attribute(line, symbolize_names)
      attribute_list << attribute
    end
  end

  attribute_list
end

#parse_line_attributes(buffer, regexp) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cf_script/output/parser/attributes.rb', line 29

def parse_line_attributes(buffer, regexp)
  if matched = buffer.match(regexp)
    attribute_list = CfScript::AttributeList.new

    matched.names.each do |name|
      attribute_list << CfScript::Attribute.new(
        symbolize(name),
        matched[name].strip
      )
    end

    attribute_list
  end
end