Class: Hawktui::StreamingTable::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/hawktui/streaming_table/cell.rb

Overview

Public: Represents a single cell in a table. Holds the cell’s value and optional color, and can return both in a consistent format.

Examples

cell = Hawktui::StreamingTable::Cell.new("Hello")
cell.value  # => "Hello"
cell.color  # => nil

colored_cell = Hawktui::StreamingTable::Cell.new(value: "Error", color: :red)
colored_cell.value  # => "Error"
colored_cell.color  # => :red

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_or_hash) ⇒ Cell

Public: Create a new Cell object from either a raw value or a Hash with ‘:value` and `:color` keys.

value_or_hash - A raw value (e.g., String, Integer) or a Hash of the form:

{ value: <String/Integer>, color: <Symbol/Integer> }.

Examples

Cell.new("Hello")
Cell.new(value: "Hello", color: :blue)

Returns a new Cell instance.



33
34
35
# File 'lib/hawktui/streaming_table/cell.rb', line 33

def initialize(value_or_hash)
  @value, @color = extract_value_and_color(value_or_hash)
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



19
20
21
# File 'lib/hawktui/streaming_table/cell.rb', line 19

def color
  @color
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/hawktui/streaming_table/cell.rb', line 19

def value
  @value
end

Instance Method Details

#extract_value_and_color(value_or_hash) ⇒ Object

Internal: Extract the cell’s value and color from the given parameter.

If value_or_hash is a Hash, expects :value and :color keys.

value_or_hash - A raw value or a Hash with :value and :color.

Returns an Array [value, color].



43
44
45
46
47
48
49
50
# File 'lib/hawktui/streaming_table/cell.rb', line 43

def extract_value_and_color(value_or_hash)
  case value_or_hash
  when Hash
    [value_or_hash[:value], value_or_hash[:color]]
  else
    [value_or_hash, nil]
  end
end