Class: MetricFu::Saikuro::ParsingElement

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

Constant Summary collapse

TYPE_REGEX =
/Type:(.*) Name/
NAME_REGEX =
/Name:(.*) Complexity/
COMPLEXITY_REGEX =
/Complexity:(.*) Lines/
LINES_REGEX =
/Lines:(.*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ ParsingElement

Returns a new instance of ParsingElement.



230
231
232
233
234
235
236
237
# File 'lib/generators/saikuro.rb', line 230

def initialize(line)
  @line = line
  @element_type = line.match(TYPE_REGEX)[1].strip
  @name = line.match(NAME_REGEX)[1].strip
  @complexity = line.match(COMPLEXITY_REGEX)[1].strip
  @lines = line.match(LINES_REGEX)[1].strip
  @defs = []
end

Instance Attribute Details

#complexityObject (readonly)

Returns the value of attribute complexity.



227
228
229
# File 'lib/generators/saikuro.rb', line 227

def complexity
  @complexity
end

#defsObject (readonly)

Returns the value of attribute defs.



227
228
229
# File 'lib/generators/saikuro.rb', line 227

def defs
  @defs
end

#element_typeObject (readonly)

Returns the value of attribute element_type.



227
228
229
# File 'lib/generators/saikuro.rb', line 227

def element_type
  @element_type
end

#linesObject (readonly)

Returns the value of attribute lines.



227
228
229
# File 'lib/generators/saikuro.rb', line 227

def lines
  @lines
end

#nameObject

Returns the value of attribute name.



228
229
230
# File 'lib/generators/saikuro.rb', line 228

def name
  @name
end

Instance Method Details

#<<(line) ⇒ Object



239
240
241
# File 'lib/generators/saikuro.rb', line 239

def <<(line)
  @defs << Saikuro::ParsingElement.new(line)
end

#to_hObject



243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/generators/saikuro.rb', line 243

def to_h
  base = {:name => @name, :complexity => @complexity.to_i, :lines => @lines.to_i}
  unless @defs.empty?
    defs = @defs.map do |my_def|
      my_def = my_def.to_h
      my_def.delete(:defs)
      my_def
    end
    base[:defs] = defs
  end
  return base
end