Class: Converter
- Inherits:
-
Object
- Object
- Converter
- Defined in:
- lib/bvm/converter.rb
Instance Attribute Summary collapse
-
#color_adjustment ⇒ Object
Returns the value of attribute color_adjustment.
-
#color_metric ⇒ Object
Returns the value of attribute color_metric.
-
#invert_color_metric ⇒ Object
Returns the value of attribute invert_color_metric.
-
#jar ⇒ Object
Returns the value of attribute jar.
-
#size_metric ⇒ Object
Returns the value of attribute size_metric.
Instance Method Summary collapse
- #build_output(resource, jar, size, color, adjust) ⇒ Object
- #convert(input) ⇒ Object
- #find_metric(metrics, key) ⇒ Object
-
#initialize ⇒ Converter
constructor
A new instance of Converter.
- #parse_package(full_name) ⇒ Object
- #parse_xml(input) ⇒ Object
Constructor Details
#initialize ⇒ Converter
Returns a new instance of Converter.
10 11 12 13 14 15 16 |
# File 'lib/bvm/converter.rb', line 10 def initialize @jar = 'jar' @size_metric = 'ncloc' @color_metric = 'coverage' @color_adjustment = 0.0 @invert_color_metric = false end |
Instance Attribute Details
#color_adjustment ⇒ Object
Returns the value of attribute color_adjustment.
7 8 9 |
# File 'lib/bvm/converter.rb', line 7 def color_adjustment @color_adjustment end |
#color_metric ⇒ Object
Returns the value of attribute color_metric.
6 7 8 |
# File 'lib/bvm/converter.rb', line 6 def color_metric @color_metric end |
#invert_color_metric ⇒ Object
Returns the value of attribute invert_color_metric.
8 9 10 |
# File 'lib/bvm/converter.rb', line 8 def invert_color_metric @invert_color_metric end |
#jar ⇒ Object
Returns the value of attribute jar.
4 5 6 |
# File 'lib/bvm/converter.rb', line 4 def jar @jar end |
#size_metric ⇒ Object
Returns the value of attribute size_metric.
5 6 7 |
# File 'lib/bvm/converter.rb', line 5 def size_metric @size_metric end |
Instance Method Details
#build_output(resource, jar, size, color, adjust) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bvm/converter.rb', line 33 def build_output(resource, jar, size, color, adjust) package = parse_package resource[:key][0] name = resource[:name][0] unless resource[:msr].nil? size_metric = find_metric resource[:msr], size color_metric = find_metric resource[:msr], color color_metric *= -1 unless not @invert_color_metric color_metric += adjust %Q/#{size_metric},#{color_metric},"#{jar}","#{package}","#{name}"\n/ else %Q/1.0,#{adjust},"NotFound","#{package}","#{name}"\n/ end end |
#convert(input) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bvm/converter.rb', line 18 def convert(input) output = "" metrics = parse_xml input unless metrics[:resource].nil? metrics[:resource].each do |resource| output << build_output(resource, @jar, @size_metric, @color_metric, @color_adjustment) end end output end |
#find_metric(metrics, key) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/bvm/converter.rb', line 49 def find_metric(metrics, key) found_metric = 0.0 metrics.each do |metric| if key == metric[:key][0] then found_metric = metric[:val][0].to_f end end found_metric end |
#parse_package(full_name) ⇒ Object
59 60 61 62 |
# File 'lib/bvm/converter.rb', line 59 def parse_package(full_name) temp = /^.*\./.match full_name /^.*[^\.]/.match(temp.to_s) end |
#parse_xml(input) ⇒ Object
29 30 31 |
# File 'lib/bvm/converter.rb', line 29 def parse_xml(input) XmlSimple.xml_in input, { 'GroupTags' => { 'resources' => 'resource' }, 'KeyToSymbol' => true } end |