Class: Coloration::Style
Instance Attribute Summary collapse
-
#background ⇒ Object
Returns the value of attribute background.
-
#bold ⇒ Object
Returns the value of attribute bold.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#foreground ⇒ Object
Returns the value of attribute foreground.
-
#inverse ⇒ Object
Returns the value of attribute inverse.
-
#italic ⇒ Object
Returns the value of attribute italic.
-
#strike ⇒ Object
Returns the value of attribute strike.
-
#underline ⇒ Object
Returns the value of attribute underline.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(obj = nil, bg = nil) ⇒ Style
constructor
A new instance of Style.
- #initialize_from_hash(h, bg = nil) ⇒ Object
Constructor Details
#initialize(obj = nil, bg = nil) ⇒ Style
Returns a new instance of Style.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/coloration/style.rb', line 6 def initialize(obj=nil, bg=nil) if obj case obj when String initialize_from_hash({ :foreground => obj }, bg) when Hash initialize_from_hash(obj, bg) end end end |
Instance Attribute Details
#background ⇒ Object
Returns the value of attribute background.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def background @background end |
#bold ⇒ Object
Returns the value of attribute bold.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def bold @bold end |
#comment ⇒ Object
Returns the value of attribute comment.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def comment @comment end |
#foreground ⇒ Object
Returns the value of attribute foreground.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def foreground @foreground end |
#inverse ⇒ Object
Returns the value of attribute inverse.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def inverse @inverse end |
#italic ⇒ Object
Returns the value of attribute italic.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def italic @italic end |
#strike ⇒ Object
Returns the value of attribute strike.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def strike @strike end |
#underline ⇒ Object
Returns the value of attribute underline.
4 5 6 |
# File 'lib/coloration/style.rb', line 4 def underline @underline end |
Instance Method Details
#blank? ⇒ Boolean
32 33 34 |
# File 'lib/coloration/style.rb', line 32 def blank? foreground.nil? && background.nil? end |
#initialize_from_hash(h, bg = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/coloration/style.rb', line 17 def initialize_from_hash(h, bg=nil) h.each do |key, value| if key == :fg key = :foreground end if key == :bg key = :background end if ["foreground", "background"].include?(key.to_s) && value.is_a?(String) value = Color::RGBA.from_html(value, bg) end send("#{key}=", value) end end |