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 ⇒ Object
- #to_s ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(*args, value: nil, at: Time.now) ⇒ Event
Returns a new instance of 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
#at ⇒ Object
Returns the value of attribute at.
5 6 7 |
# File 'lib/simplefeed/event.rb', line 5 def at @at end |
#value ⇒ Object
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 |
#hash ⇒ Object
43 44 45 |
# File 'lib/simplefeed/event.rb', line 43 def hash self.value.hash end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/simplefeed/event.rb', line 67 def inspect super end |
#time ⇒ Object
22 23 24 |
# File 'lib/simplefeed/event.rb', line 22 def time Time.at(at) end |
#to_color_s ⇒ Object
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_h ⇒ Object
39 40 41 |
# File 'lib/simplefeed/event.rb', line 39 def to_h { value: value, at: at, time: time } end |
#to_json ⇒ Object
47 48 49 |
# File 'lib/simplefeed/event.rb', line 47 def to_json to_h.to_json end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/simplefeed/event.rb', line 55 def to_s "<SimpleFeed::Event: value='#{value}', at='#{at}', time='#{time}'>" end |
#to_yaml ⇒ Object
51 52 53 |
# File 'lib/simplefeed/event.rb', line 51 def to_yaml YAML.dump(to_h) end |