Class: Palette::Rule
- Inherits:
-
Object
- Object
- Palette::Rule
- Defined in:
- lib/palette/rule.rb
Constant Summary collapse
- @@max_length =
0
Instance Attribute Summary collapse
-
#bg ⇒ Object
readonly
Returns the value of attribute bg.
-
#fg ⇒ Object
readonly
Returns the value of attribute fg.
-
#gui ⇒ Object
readonly
Returns the value of attribute gui.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, *args) ⇒ Rule
constructor
A new instance of Rule.
- #to_s ⇒ Object
Constructor Details
#initialize(name, *args) ⇒ Rule
Returns a new instance of Rule.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/palette/rule.rb', line 6 def initialize(name, *args) = args.last.is_a?(Hash) ? args.pop : {} @name = name.to_s @@max_length = @name.length if @name.length > @@max_length @fg = [:fg] || args.first @bg = [:bg] || (args.length > 1 ? args.last : nil) @gui = [:gui] end |
Instance Attribute Details
#bg ⇒ Object (readonly)
Returns the value of attribute bg.
4 5 6 |
# File 'lib/palette/rule.rb', line 4 def bg @bg end |
#fg ⇒ Object (readonly)
Returns the value of attribute fg.
4 5 6 |
# File 'lib/palette/rule.rb', line 4 def fg @fg end |
#gui ⇒ Object (readonly)
Returns the value of attribute gui.
4 5 6 |
# File 'lib/palette/rule.rb', line 4 def gui @gui end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/palette/rule.rb', line 4 def name @name end |
Instance Method Details
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/palette/rule.rb', line 18 def to_s return "" if fg.nil? && bg.nil? && gui.nil? output = ["hi #{sprintf("%-#{@@max_length}s", name)}"] if fg color = Palette::Color.new(fg) output << %{guifg=#{sprintf("%-7s", color.to_hex)}} output << %{ctermfg=#{sprintf("%-4s", color.to_cterm)}} end if bg color = Palette::Color.new(bg) output << %{guibg=#{sprintf("%-7s", color.to_hex)}} output << %{ctermbg=#{sprintf("%-4s", color.to_cterm)}} end @gui ||= "none" output << %{gui=#{gui.upcase}} if gui =~ /italic/ output << %{cterm=NONE} else output << %{cterm=#{gui.upcase}} end output.join(" ").strip end |