class SimpleFeed::Event
Constants
- COLOR_MAP
Attributes
is_time[RW]
at[RW]
value[RW]
Public Class Methods
new(*args, value: nil, at: Time.now)
click to toggle source
# File lib/simplefeed/event.rb, line 25 def initialize(*args, value: nil, at: Time.now) if args && !args.empty? self.value = args[0] self.at = args[1] end self.value ||= value self.at ||= at self.at = self.at.to_f validate! end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/simplefeed/event.rb, line 47 def <=>(other) -self.at <=> -other.at end
==(other)
click to toggle source
# File lib/simplefeed/event.rb, line 55 def ==(other) other.is_a?(SimpleFeed::Event) && self.value == other.value end
eql?(other)
click to toggle source
# File lib/simplefeed/event.rb, line 51 def eql?(other) self == other end
hash()
click to toggle source
# File lib/simplefeed/event.rb, line 60 def hash self.value.hash end
inspect()
click to toggle source
Calls superclass method
# File lib/simplefeed/event.rb, line 106 def inspect super end
time()
click to toggle source
# File lib/simplefeed/event.rb, line 39 def time return nil unless Event.is_time[at] Time.at(at) rescue ArgumentError nil end
to_color_s()
click to toggle source
# File lib/simplefeed/event.rb, line 95 def to_color_s return @to_color_s if @to_color_s output = StringIO.new to_s.split(/[\[\]]/).each_with_index do |word, index| output.print(COLOR_MAP[index]&.call(word) || word.cyan) end output.print '>' @to_color_s = output.string end
to_h()
click to toggle source
# File lib/simplefeed/event.rb, line 72 def to_h return @to_h if @to_h @to_h ||= { value: value, at: at } @to_h.merge!(time: time) if time @to_h end
to_json(*_args)
click to toggle source
# File lib/simplefeed/event.rb, line 64 def to_json(*_args) to_h.to_json end
to_s()
click to toggle source
# File lib/simplefeed/event.rb, line 80 def to_s return @to_s if @to_s output = StringIO.new output.print "<SimpleFeed::Event: " output.print(time.nil? ? "[#{at}]" : "[#{time&.strftime(::SimpleFeed::TIME_FORMAT)}]") output.print " -> [#{value}] " @to_s = output.string end
to_yaml()
click to toggle source
# File lib/simplefeed/event.rb, line 68 def to_yaml YAML.dump(to_h) end
Private Instance Methods
validate!()
click to toggle source
# File lib/simplefeed/event.rb, line 112 def validate! unless self.value && self.at raise ArgumentError, "Required arguments missing, value=[#{value}], at=[#{at}]" end end