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.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/beeminder/goals.rb', line 210 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.
198 199 200 |
# File 'lib/beeminder/goals.rb', line 198 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.
208 209 210 |
# File 'lib/beeminder/goals.rb', line 208 def goal @goal end |
#id ⇒ String (readonly)
Returns A unique ID, used to identify a datapoint when deleting or editing it.
201 202 203 |
# File 'lib/beeminder/goals.rb', line 201 def id @id end |
#timestamp ⇒ DateTime
Returns Time of the datapoint.
192 193 194 |
# File 'lib/beeminder/goals.rb', line 192 def @timestamp end |
#updated_at ⇒ DateTime (readonly)
Returns The time that this datapoint was entered or last updated.
204 205 206 |
# File 'lib/beeminder/goals.rb', line 204 def updated_at @updated_at end |
#value ⇒ Numeric
Returns Value of the datapoint.
195 196 197 |
# File 'lib/beeminder/goals.rb', line 195 def value @value end |
Instance Method Details
#to_hash ⇒ Hash
Convert datapoint to hash for POSTing.
233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/beeminder/goals.rb', line 233 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 |