Class: SimpleFeed::Event
- Inherits:
-
Object
- Object
- SimpleFeed::Event
- Includes:
- Comparable
- Defined in:
- lib/simplefeed/event.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
Returns the value of attribute at.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(*args, value: nil, at: Time.now) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
- #time ⇒ Object
- #to_color_s ⇒ Object
- #to_h ⇒ Object
- #to_json(*_args) ⇒ Object
- #to_s ⇒ Object
- #to_yaml ⇒ Object
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
#at ⇒ Object
Returns the value of attribute at.
7 8 9 |
# File 'lib/simplefeed/event.rb', line 7 def at @at end |
#value ⇒ Object
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
32 33 34 |
# File 'lib/simplefeed/event.rb', line 32 def eql?(other) self == other end |
#hash ⇒ Object
45 46 47 |
# File 'lib/simplefeed/event.rb', line 45 def hash self.value.hash end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/simplefeed/event.rb', line 69 def inspect super end |
#time ⇒ Object
24 25 26 |
# File 'lib/simplefeed/event.rb', line 24 def time Time.at(at) end |
#to_color_s ⇒ Object
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_h ⇒ Object
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_s ⇒ Object
57 58 59 |
# File 'lib/simplefeed/event.rb', line 57 def to_s "<SimpleFeed::Event: value='#{value}', at='#{at}', time='#{time}'>" end |
#to_yaml ⇒ Object
53 54 55 |
# File 'lib/simplefeed/event.rb', line 53 def to_yaml YAML.dump(to_h) end |