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


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

def initialize(*args, value: nil, at: Time.now)
  if args && args.size > 0
    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


5
6
7
# File 'lib/simplefeed/event.rb', line 5

def at
  @at
end

#valueObject

Returns the value of attribute value


5
6
7
# File 'lib/simplefeed/event.rb', line 5

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object


26
27
28
# File 'lib/simplefeed/event.rb', line 26

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

#==(other) ⇒ Object


34
35
36
37
# File 'lib/simplefeed/event.rb', line 34

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

#eql?(other) ⇒ Boolean


30
31
32
# File 'lib/simplefeed/event.rb', line 30

def eql?(other)
  self == other
end

#hashObject


43
44
45
# File 'lib/simplefeed/event.rb', line 43

def hash
  self.value.hash
end

#inspectObject


67
68
69
# File 'lib/simplefeed/event.rb', line 67

def inspect
  super
end

#timeObject


22
23
24
# File 'lib/simplefeed/event.rb', line 22

def time
  Time.at(at)
end

#to_color_sObject


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

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


39
40
41
# File 'lib/simplefeed/event.rb', line 39

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

#to_jsonObject


47
48
49
# File 'lib/simplefeed/event.rb', line 47

def to_json
  to_h.to_json
end

#to_sObject


55
56
57
# File 'lib/simplefeed/event.rb', line 55

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

#to_yamlObject


51
52
53
# File 'lib/simplefeed/event.rb', line 51

def to_yaml
  YAML.dump(to_h)
end