Class: Nyaplot::Series

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

Instance Method Summary collapse

Constructor Details

#initialize(label, arr) ⇒ Series

Returns a new instance of Series



191
192
193
194
# File 'lib/nyaplot/data.rb', line 191

def initialize(label, arr)
  @arr = arr
  @label = label
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



218
219
220
221
222
223
224
# File 'lib/nyaplot/data.rb', line 218

def method_missing(meth, *args, &block)
  if @arr.respond_to?(meth)
    @arr.send(meth, *args, &block)
  else
    super(meth, *args, &block)
  end
end

Instance Method Details

#each(&block) ⇒ Object



187
188
189
# File 'lib/nyaplot/data.rb', line 187

def each(&block)
  @arr.each(&block)
end

#labelObject



214
215
216
# File 'lib/nyaplot/data.rb', line 214

def label
  @label
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


226
227
228
229
# File 'lib/nyaplot/data.rb', line 226

def respond_to?(meth)
  return true if @arr.respond_to?(meth)
  super(meth)
end

#to_aObject



210
211
212
# File 'lib/nyaplot/data.rb', line 210

def to_a
  @arr
end

#to_html(threshold = 15) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/nyaplot/data.rb', line 196

def to_html(threshold=15)
  html = '<table><tr><th>' + label.to_s + '</th></tr>>'
  @arr.each_with_index do |el,i|
    next if threshold < i && i < @arr.length-1
    content = i == threshold ? '...' : el.to_s
    html.concat('<tr><td>' + content  + '</td></tr>')
  end
  html += '</table>'
end

#to_json(*args) ⇒ Object



206
207
208
# File 'lib/nyaplot/data.rb', line 206

def to_json(*args)
  @arr.to_json
end