Class: SimpleFeed::Event

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/simplefeed/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, value: nil, at: Time.now) ⇒ Event

Returns a new instance of Event.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simplefeed/event.rb', line 10

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

Instance Attribute Details

#atObject

Returns the value of attribute at.



7
8
9
# File 'lib/simplefeed/event.rb', line 7

def at
  @at
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/simplefeed/event.rb', line 7

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/simplefeed/event.rb', line 28

def <=>(other)
  -self.at <=> -other.at
end

#==(other) ⇒ Object



36
37
38
39
# File 'lib/simplefeed/event.rb', line 36

def ==(other)
  other.is_a?(SimpleFeed::Event) &&
    self.value == other.value
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/simplefeed/event.rb', line 32

def eql?(other)
  self == other
end

#hashObject



45
46
47
# File 'lib/simplefeed/event.rb', line 45

def hash
  self.value.hash
end

#inspectObject



69
70
71
# File 'lib/simplefeed/event.rb', line 69

def inspect
  super
end

#timeObject



24
25
26
# File 'lib/simplefeed/event.rb', line 24

def time
  Time.at(at)
end

#to_color_sObject



61
62
63
64
65
66
67
# File 'lib/simplefeed/event.rb', line 61

def to_color_s
  counter = 0
  to_s.split(/[']/).map do |word|
    counter += 1
    counter.even? ? word.yellow.bold : word.blue
  end.join('')
end

#to_hObject



41
42
43
# File 'lib/simplefeed/event.rb', line 41

def to_h
  { value: value, at: at, time: time }
end

#to_json(*_args) ⇒ Object



49
50
51
# File 'lib/simplefeed/event.rb', line 49

def to_json(*_args)
  to_h.to_json
end

#to_sObject



57
58
59
# File 'lib/simplefeed/event.rb', line 57

def to_s
  "<SimpleFeed::Event: value='#{value}', at='#{at}', time='#{time}'>"
end

#to_yamlObject



53
54
55
# File 'lib/simplefeed/event.rb', line 53

def to_yaml
  YAML.dump(to_h)
end