Class: String
Instance Method Summary collapse
-
#colour_codes ⇒ Object
with thanks to
.
- #colours ⇒ Object
- #has_colour?(colour_key) ⇒ Boolean
- #highlight_colour_codes ⇒ Object
- #method_missing(method_sym, *arguments, &black) ⇒ Object
- #swatch ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &black) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/patches/string.rb', line 62 def method_missing(method_sym, *arguments, &black) super unless has_colour?(method_sym) colour_data = colours[method_sym] colour = colour_codes[colour_data[:colour]] unless colour_data[:highlight] return Rainbow(self).color(colour) else coloured_string = Rainbow(self).color(colour) return "\e[1m#{coloured_string}\033[0m" #highlight_colour = highlight_colour_codes[colour_data[:colour]] #highlight_string = Rainbow(self).color(highlight_colour).bg(colour) return "\e[1m#{highlight_string}\033[0m" end end |
Instance Method Details
#colour_codes ⇒ Object
with thanks to
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/patches/string.rb', line 4 def colour_codes { :yellow => "#b58900", :orange => "#cb4b16", :red => "#dc322f", :magenta => "#d33682", :violet => "#6c71c4", :blue => "#268bd2", :cyan => "#2aa198", :green => "#859900", :white => "#ffffff" } end |
#colours ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/patches/string.rb', line 31 def colours { :informational => { :colour => :yellow }, :failure => { :colour => :red }, :success => { :colour => :green }, :title => { :colour => :green }, :command => { :colour => :cyan, :highlight => true }, :danger => { :colour => :red }, :warning => { :colour => :orange }, :friendly => { :colour => :green }, :menu_item_green => { :colour => :green }, :menu_title_orange => { :colour => :orange, :highlight => true }, :menu_item_orange => { :colour => :orange }, :menu_title_green => { :colour => :green, :highlight => true }, :menu_item_white => { :colour => :white }, :menu_item_yellow => { :colour => :yellow }, :menu_item_cyan => { :colour => :cyan }, :selections => { :colour => :cyan }, :menu_title_cyan => { :colour => :cyan, :highlight => true }, :headsup => { :colour => :orange, :highlight => true }, :menu_item_magenta => { :colour => :magenta }, :cyan => { :colour => :cyan }, :yellow => { :colour => :yellow }, :orange => { :colour => :orange } } end |
#has_colour?(colour_key) ⇒ Boolean
58 59 60 |
# File 'lib/patches/string.rb', line 58 def has_colour?(colour_key) colours.has_key?(colour_key) end |
#highlight_colour_codes ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/patches/string.rb', line 18 def highlight_colour_codes { :yellow => "#002b36", :orange => "#073642", :red => "#586e75", :magenta => "#657b83", :violet => "#839496", :blue => "#93a1a1", :cyan => "#eee8d5", :green => "#fdf6e3" } end |
#swatch ⇒ Object
80 81 82 83 84 |
# File 'lib/patches/string.rb', line 80 def swatch colours.each { |colour_key, colour_attributes| puts "#{colour_key} : #{send(colour_key)}" } end |