Class: Railswatch::Events::Record
- Inherits:
-
Object
- Object
- Railswatch::Events::Record
- Defined in:
- lib/railswatch/events/record.rb
Constant Summary collapse
- DEFAULT_COLOR =
'#FF00FF'- DEFAULT_LABEL_COLOR =
'#FF00FF'- DEFAULT_LABEL_ORIENTATION =
'horizontal'
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Class Method Summary collapse
Instance Method Summary collapse
- #datetimei ⇒ Object
-
#initialize(record) ⇒ Record
constructor
A new instance of Record.
- #options ⇒ Object
- #to_annotation ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(record) ⇒ Record
Returns a new instance of Record.
27 28 29 |
# File 'lib/railswatch/events/record.rb', line 27 def initialize(record) @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
6 7 8 |
# File 'lib/railswatch/events/record.rb', line 6 def record @record end |
Class Method Details
.all ⇒ Object
22 23 24 |
# File 'lib/railswatch/events/record.rb', line 22 def all Railswatch::Models::EventRecord.order(:occurred_at).map { |record| new(record) } end |
.create(name:, datetimei: Time.now.to_i, options: {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/railswatch/events/record.rb', line 13 def create(name:, datetimei: Time.now.to_i, options: {}) model = Railswatch::Models::EventRecord.create!( name: name, options: , occurred_at: Railswatch::Utils.from_datetimei(datetimei.to_i) ) new(model) end |
Instance Method Details
#datetimei ⇒ Object
33 34 35 |
# File 'lib/railswatch/events/record.rb', line 33 def datetimei record.occurred_at.to_i end |
#options ⇒ Object
37 38 39 |
# File 'lib/railswatch/events/record.rb', line 37 def (record. || {}).deep_stringify_keys end |
#to_annotation ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/railswatch/events/record.rb', line 50 def to_annotation { x: datetimei * 1000, borderColor: ['borderColor'] || DEFAULT_COLOR, label: { borderColor: .dig('label', 'borderColor') || DEFAULT_LABEL_COLOR, orientation: .dig('label', 'orientation') || DEFAULT_LABEL_ORIENTATION, text: .dig('label', 'text') || name } } end |
#value ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/railswatch/events/record.rb', line 41 def value { name: name, datetime: record.occurred_at, datetimei: datetimei, options: } end |