class Daygram::Database::Dataset

Public Class Methods

new(dataset) click to toggle source
# File lib/daygram/database/dataset.rb, line 6
def initialize(dataset)
  @data = dataset
end

Public Instance Methods

diary_fields() click to toggle source
# File lib/daygram/database/dataset.rb, line 10
def diary_fields
  [:date, :created, :updated, :content]
end
format_output(options) click to toggle source
# File lib/daygram/database/dataset.rb, line 49
def format_output options
  if options[:format] == 'hash'
    self.to_hash
  elsif options[:format] == 'json'
    self.to_json
  elsif options[:format] == 'table'
    Terminal::Table.new :title => "Daygram Diary", :headings => diary_fields, :rows => self.to_array
  else
    self.to_s
  end
end
to_a()
Alias for: to_array
to_array() click to toggle source
# File lib/daygram/database/dataset.rb, line 31
def to_array
  arr = []
  @data.each do |entry|
    row = []
    diary_fields.each do |field|
      row << entry[field]
    end
    arr << row
  end

  arr
end
Also aliased as: to_a
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/daygram/database/dataset.rb, line 26
def to_hash
  @data.to_hash(:date)
end
Also aliased as: to_h
to_json() click to toggle source
# File lib/daygram/database/dataset.rb, line 45
def to_json
  to_hash.to_json
end
to_s()
Alias for: to_string
to_string() click to toggle source
# File lib/daygram/database/dataset.rb, line 14
def to_string
  str = ""
  @data.each do |entry|
    str << "#{entry[:date]} | Created: #{entry[:created]} | Updated: #{entry[:updated]}\n"
    str << "#{entry[:content]}\n"
    str << "\n\n"
  end

  str
end
Also aliased as: to_s