mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 05:16:39 +00:00
allow date/time and label to be changed on
Redistat::Key and Redistat::Event objects
This commit is contained in:
@@ -2,26 +2,42 @@ module Redistat
|
||||
class Event
|
||||
|
||||
attr_reader :scope
|
||||
attr_reader :label
|
||||
attr_reader :key
|
||||
attr_reader :options
|
||||
|
||||
attr_accessor :data
|
||||
attr_accessor :options
|
||||
|
||||
def initialize(scope, label = nil, data = {}, date = nil, options = {})
|
||||
@options = options
|
||||
@scope = scope
|
||||
@key = Key.new(scope, label, date, options)
|
||||
@label = @key.label
|
||||
#TODO ...intialize Redistat::Event
|
||||
end
|
||||
|
||||
def date
|
||||
@key.date.to_date
|
||||
end
|
||||
|
||||
def time
|
||||
@key.date.to_time
|
||||
end
|
||||
|
||||
def date=(input)
|
||||
@key.date = input
|
||||
end
|
||||
|
||||
alias :time :date
|
||||
alias :time= :date=
|
||||
|
||||
def label
|
||||
@key.label
|
||||
end
|
||||
|
||||
def label_hash
|
||||
@key.label_hash
|
||||
end
|
||||
|
||||
def label=(input)
|
||||
@key.label = input
|
||||
end
|
||||
|
||||
|
||||
def save
|
||||
|
||||
end
|
||||
|
||||
@@ -2,22 +2,30 @@ module Redistat
|
||||
class Key
|
||||
|
||||
attr_accessor :scope
|
||||
attr_accessor :label
|
||||
attr_accessor :date
|
||||
|
||||
def initialize(scope, label = nil, date = nil, options = {})
|
||||
@scope = scope
|
||||
@label = Label.create(label) if !label.nil?
|
||||
@date = Date.new(date ||= Time.now) # Redistat::Date, not ::Date
|
||||
self.label = label if !label.nil?
|
||||
self.date = date ||= Time.now
|
||||
@options = options
|
||||
end
|
||||
|
||||
#TODO figure out if direct access to the label object is desired or not
|
||||
# def label
|
||||
# if !@label.nil?
|
||||
# (@options[:hash_label] ||= true) ? @label.hash : @label.name
|
||||
# end
|
||||
# end
|
||||
def date=(input)
|
||||
@date = (input.instance_of?(Redistat::Date)) ? input : Date.new(input) # Redistat::Date, not ::Date
|
||||
end
|
||||
|
||||
def label
|
||||
@label.name
|
||||
end
|
||||
|
||||
def label_hash
|
||||
@label.hash
|
||||
end
|
||||
|
||||
def label=(input)
|
||||
@label = (input.instance_of?(Redistat::Label)) ? input : Label.create(input)
|
||||
end
|
||||
|
||||
def to_s(depth = nil)
|
||||
depth ||= @options[:depth] if !@options[:depth].nil?
|
||||
|
||||
Reference in New Issue
Block a user