Class: Fat::Color

Inherits:
Fit::PrimitiveFixture show all
Defined in:
lib/fat/color.rb

Constant Summary

Constants inherited from Fit::Fixture

Fit::Fixture::GRAY, Fit::Fixture::GREEN, Fit::Fixture::RED, Fit::Fixture::YELLOW

Instance Attribute Summary

Attributes inherited from Fit::Fixture

#args, #counts, #listener, #summary

Instance Method Summary collapse

Methods inherited from Fit::PrimitiveFixture

#check, #check_boolean, #check_value, #parse_boolean, #parse_double, #parse_integer

Methods inherited from Fit::Fixture

camel, #check, #do_cells, #do_table, #do_tables, #error, escape, #exception, #find_class, #fixture_name, #get_args_for_table, #get_linked_fixture_with_args, gray, #ignore, #info, #initialize, #interpret_following_tables, #interpret_tables, label, metadata, #parse, #right, #total_errors, #totals, #wrong

Constructor Details

This class inherits a constructor from Fit::Fixture

Instance Method Details

#color(cell) ⇒ Object



22
23
24
25
26
# File 'lib/fat/color.rb', line 22

def color cell
  b = extract cell.tag, 'bgcolor="', 'white'
  f = extract cell.body, '<font color="', 'black'
  f == 'black' ? b : "#{f}/#{b}"
end

#decode(code) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/fat/color.rb', line 33

def decode code
  case code
    when Fit::Fixture::RED then 'red'
    when Fit::Fixture::GREEN then 'green'
    when Fit::Fixture::YELLOW then 'yellow'
    when Fit::Fixture::GRAY then 'gray'
    when '#808080' then 'gray'
    else code
  end
end

#do_cell(cell, column_index) ⇒ Object



19
20
21
# File 'lib/fat/color.rb', line 19

def do_cell cell, column_index
  check_value cell, color(@actual_row.parts.at(column_index))
end

#do_row(row) ⇒ Object



15
16
17
18
# File 'lib/fat/color.rb', line 15

def do_row row
  super
  @actual_row = @actual_row.more
end

#do_rows(rows) ⇒ Object



10
11
12
13
14
# File 'lib/fat/color.rb', line 10

def do_rows rows
  @actual_row = Table.table.parts
  raise "wrong size table" if not rows.size == @actual_row.size
  super
end

#extract(text, pattern, default_color) ⇒ Object



27
28
29
30
31
32
# File 'lib/fat/color.rb', line 27

def extract text, pattern, default_color
  index = text.index pattern
  return default_color if index.nil?
  index += pattern.size
  decode text[index..(index + 6)]
end