Class: Flukso::UTCReading
- Inherits:
-
Object
- Object
- Flukso::UTCReading
- Defined in:
- lib/flukso/reading.rb
Instance Attribute Summary collapse
-
#utc_timestamp ⇒ Object
Returns the value of attribute utc_timestamp.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #dayOfWeek ⇒ Object
-
#initialize(utc_timestamp, value) ⇒ UTCReading
constructor
A new instance of UTCReading.
- #isOnDay?(day, month, year) ⇒ Boolean
- #nan? ⇒ Boolean
- #period ⇒ Object
- #time ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(utc_timestamp, value) ⇒ UTCReading
Returns a new instance of UTCReading.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/flukso/reading.rb', line 27 def initialize(, value) # sanity checks. raise Flukso::General, "Invalid reading timestamp: #{}" if < 0; #raise Flukso::General, "Invalid reading value: #{value}" if value.class != Fixnum || value < 0; @utc_timestamp = .to_i; if value =~ /^nan$/i @value=0.0/0.0 # Workaround: Ruby does not allow to assign NaN directly. else @value = value end end |
Instance Attribute Details
#utc_timestamp ⇒ Object
Returns the value of attribute utc_timestamp.
26 27 28 |
# File 'lib/flukso/reading.rb', line 26 def @utc_timestamp end |
#value ⇒ Object
Returns the value of attribute value.
26 27 28 |
# File 'lib/flukso/reading.rb', line 26 def value @value end |
Instance Method Details
#dayOfWeek ⇒ Object
47 48 49 50 |
# File 'lib/flukso/reading.rb', line 47 def dayOfWeek currenttime=Time.at(@utc_timestamp); return currenttime.strftime("%a"); end |
#isOnDay?(day, month, year) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/flukso/reading.rb', line 51 def isOnDay?(day,month,year) starttime=Time.mktime(year, month, day, 0, 0); endtime=Time.mktime(year, month, day, 23, 59); event=Time.at(@utc_timestamp); if ((starttime <= event) and (event <= endtime)) return true else return false end end |
#nan? ⇒ Boolean
38 39 40 |
# File 'lib/flukso/reading.rb', line 38 def nan? return (value*1.0).nan? end |
#period ⇒ Object
61 62 63 64 65 |
# File 'lib/flukso/reading.rb', line 61 def period currenttime=Time.at(@utc_timestamp); period=(currenttime.hour * 4) + (currenttime.min / 15); return period end |
#time ⇒ Object
44 45 46 |
# File 'lib/flukso/reading.rb', line 44 def time return Time.at(@utc_timestamp); end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/flukso/reading.rb', line 41 def to_s return "#{@utc_timestamp} -> #{@value}" end |