Class: Nyaplot::Color

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nyaplot/color.rb

Overview

The html interface to access Colorset

Instance Method Summary collapse

Constructor Details

#initialize(arr) ⇒ Color

Returns a new instance of Color



60
61
62
# File 'lib/nyaplot/color.rb', line 60

def initialize(arr)
  @source = arr
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/nyaplot/color.rb', line 83

def method_missing(meth, *args, &block)
  if [:size, :length, :[]].include?(meth)
    @source.send(meth, *args, &block)
  else
    super
  end
end

Instance Method Details

#each(&bl) ⇒ Object



56
57
58
# File 'lib/nyaplot/color.rb', line 56

def each(&bl)
  @source.each(&bl)
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
# File 'lib/nyaplot/color.rb', line 91

def respond_to?(meth)
  return true if [:size, :length, :[]].include?(meth)
  super
end

#to_aObject



64
65
66
# File 'lib/nyaplot/color.rb', line 64

def to_a
  @source
end

#to_htmlString

display colorset on IRuby notebook as a html table

Returns:

  • (String)

    generated html



70
71
72
73
74
75
76
77
# File 'lib/nyaplot/color.rb', line 70

def to_html
  html = '<table><tr>'
  @source.each{|color| html.concat("<th>" + color + "</th>")}
  html.concat("</tr><tr>")
  @source.each{|color| html.concat("<td style=\"background-color:" + color + ";\">&nbsp;</td>")}
  html += '</tr></table>'
  return html
end

#to_json(*args) ⇒ Object



79
80
81
# File 'lib/nyaplot/color.rb', line 79

def to_json(*args)
  @source.to_json
end