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.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/coloration/style.rb', line 7 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.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def background @background end |
#bold ⇒ Object
Returns the value of attribute bold.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def bold @bold end |
#comment ⇒ Object
Returns the value of attribute comment.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def comment @comment end |
#foreground ⇒ Object
Returns the value of attribute foreground.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def foreground @foreground end |
#inverse ⇒ Object
Returns the value of attribute inverse.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def inverse @inverse end |
#italic ⇒ Object
Returns the value of attribute italic.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def italic @italic end |
#strike ⇒ Object
Returns the value of attribute strike.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def strike @strike end |
#underline ⇒ Object
Returns the value of attribute underline.
5 6 7 |
# File 'lib/coloration/style.rb', line 5 def underline @underline end |
Instance Method Details
#blank? ⇒ Boolean
33 34 35 |
# File 'lib/coloration/style.rb', line 33 def blank? foreground.nil? && background.nil? end |
#initialize_from_hash(h, bg = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/coloration/style.rb', line 18 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 |