Class: Beeminder::Datapoint
- Inherits:
-
Object
- Object
- Beeminder::Datapoint
- Defined in:
- lib/beeminder/goals.rb
Instance Attribute Summary collapse
-
#comment ⇒ String
An optional comment about the datapoint.
-
#goal ⇒ Beeminder::Goal
Goal this datapoint belongs to.
-
#id ⇒ String
readonly
A unique ID, used to identify a datapoint when deleting or editing it.
-
#timestamp ⇒ DateTime
Time of the datapoint.
-
#updated_at ⇒ DateTime
readonly
The time that this datapoint was entered or last updated.
-
#value ⇒ Numeric
Value of the datapoint.
Instance Method Summary collapse
-
#initialize(info = {}) ⇒ Datapoint
constructor
A new instance of Datapoint.
-
#to_hash ⇒ Hash
Convert datapoint to hash for POSTing.
Constructor Details
#initialize(info = {}) ⇒ Datapoint
Returns a new instance of Datapoint.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/beeminder/goals.rb', line 248 def initialize info={} # set variables info.each do |k,v| instance_variable_set "@#{k}", v end # defaults @timestamp ||= DateTime.now @comment ||= "" # some conversions @timestamp = DateTime.strptime(@timestamp.to_s, '%s') unless @timestamp.is_a?(Date) || @timestamp.is_a?(Time) @updated_at = DateTime.strptime(@updated_at.to_s, '%s') unless @updated_at.nil? # set timezone if possible unless @goal.nil? @timestamp = @timestamp.in_time_zone @goal.user.timezone @updated_at = @updated_at.in_time_zone @goal.user.timezone end end |
Instance Attribute Details
#comment ⇒ String
Returns An optional comment about the datapoint.
236 237 238 |
# File 'lib/beeminder/goals.rb', line 236 def comment @comment end |
#goal ⇒ Beeminder::Goal
Returns Goal this datapoint belongs to. Optional for new datapoints. Use ‘Goal#add` to add new datapoints to a goal.
246 247 248 |
# File 'lib/beeminder/goals.rb', line 246 def goal @goal end |
#id ⇒ String (readonly)
Returns A unique ID, used to identify a datapoint when deleting or editing it.
239 240 241 |
# File 'lib/beeminder/goals.rb', line 239 def id @id end |
#timestamp ⇒ DateTime
Returns Time of the datapoint.
230 231 232 |
# File 'lib/beeminder/goals.rb', line 230 def @timestamp end |
#updated_at ⇒ DateTime (readonly)
Returns The time that this datapoint was entered or last updated.
242 243 244 |
# File 'lib/beeminder/goals.rb', line 242 def updated_at @updated_at end |
#value ⇒ Numeric
Returns Value of the datapoint.
233 234 235 |
# File 'lib/beeminder/goals.rb', line 233 def value @value end |
Instance Method Details
#to_hash ⇒ Hash
Convert datapoint to hash for POSTing.
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/beeminder/goals.rb', line 271 def to_hash if not @goal.nil? and @goal.user.enforce_timezone? @timestamp = @goal.user.convert_to_timezone @timestamp end { "timestamp" => @timestamp.strftime('%s'), "value" => @value || 0, "comment" => @comment || "", } end |