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.



234
235
236
237
# File 'lib/nyaplot/data.rb', line 234

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



261
262
263
264
265
266
267
# File 'lib/nyaplot/data.rb', line 261

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



230
231
232
# File 'lib/nyaplot/data.rb', line 230

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

#labelObject



257
258
259
# File 'lib/nyaplot/data.rb', line 257

def label
  @label
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


269
270
271
272
# File 'lib/nyaplot/data.rb', line 269

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

#to_aObject



253
254
255
# File 'lib/nyaplot/data.rb', line 253

def to_a
  @arr
end

#to_html(threshold = 15) ⇒ Object



239
240
241
242
243
244
245
246
247
# File 'lib/nyaplot/data.rb', line 239

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



249
250
251
# File 'lib/nyaplot/data.rb', line 249

def to_json(*args)
  @arr.to_json
end