Class: Plushie::Type::StyleMap::Spec

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/type/style_map.rb

Overview

Immutable spec; use #with to create modified copies.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base: nil, background: nil, text_color: nil, border: nil, shadow: nil, hovered: nil, pressed: nil, disabled: nil, focused: nil) ⇒ Spec

Returns a new instance of Spec.



46
47
48
49
50
# File 'lib/plushie/type/style_map.rb', line 46

def initialize(base: nil, background: nil, text_color: nil,
  border: nil, shadow: nil, hovered: nil, pressed: nil,
  disabled: nil, focused: nil)
  super
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background

Returns:

  • (Object)

    the current value of background



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def background
  @background
end

#baseObject (readonly)

Returns the value of attribute base

Returns:

  • (Object)

    the current value of base



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def base
  @base
end

#borderObject (readonly)

Returns the value of attribute border

Returns:

  • (Object)

    the current value of border



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def border
  @border
end

#disabledObject (readonly)

Returns the value of attribute disabled

Returns:

  • (Object)

    the current value of disabled



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def disabled
  @disabled
end

#focusedObject (readonly)

Returns the value of attribute focused

Returns:

  • (Object)

    the current value of focused



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def focused
  @focused
end

#hoveredObject (readonly)

Returns the value of attribute hovered

Returns:

  • (Object)

    the current value of hovered



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def hovered
  @hovered
end

#pressedObject (readonly)

Returns the value of attribute pressed

Returns:

  • (Object)

    the current value of pressed



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def pressed
  @pressed
end

#shadowObject (readonly)

Returns the value of attribute shadow

Returns:

  • (Object)

    the current value of shadow



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def shadow
  @shadow
end

#text_colorObject (readonly)

Returns the value of attribute text_color

Returns:

  • (Object)

    the current value of text_color



44
45
46
# File 'lib/plushie/type/style_map.rb', line 44

def text_color
  @text_color
end

Instance Method Details

#to_wireHash

Returns wire-ready map with nil fields stripped.

Returns:

  • (Hash)

    wire-ready map with nil fields stripped



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/plushie/type/style_map.rb', line 58

def to_wire
  h = {}
  h[:base] = base.to_s if base
  h[:background] = background if background
  h[:text_color] = text_color if text_color
  h[:border] = Border.encode(border) if border
  h[:shadow] = Shadow.encode(shadow) if shadow
  h[:hovered] = encode_state(hovered) if hovered
  h[:pressed] = encode_state(pressed) if pressed
  h[:disabled] = encode_state(disabled) if disabled
  h[:focused] = encode_state(focused) if focused
  h
end

#with(**changes) ⇒ Object

Returns a copy with the given fields updated.



53
54
55
# File 'lib/plushie/type/style_map.rb', line 53

def with(**changes)
  self.class.new(**to_h.merge(changes))
end