Class: Hubba::Stats::HistoryItem

Inherits:
Object
  • Object
show all
Defined in:
lib/hubba/stats.rb

Overview

build history items (structs)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:, stars:) ⇒ HistoryItem

Returns a new instance of HistoryItem.



105
106
107
108
109
# File 'lib/hubba/stats.rb', line 105

def initialize( date:, stars: )
  @date  = date
  @stars = stars
  @next  = nil
end

Instance Attribute Details

#dateObject (readonly)

read-only attributes



102
103
104
# File 'lib/hubba/stats.rb', line 102

def date
  @date
end

#nextObject

read/write attributes (for double linked list/nodes/items)



103
104
105
# File 'lib/hubba/stats.rb', line 103

def next
  @next
end

#prevObject

read/write attributes (for double linked list/nodes/items)



103
104
105
# File 'lib/hubba/stats.rb', line 103

def prev
  @prev
end

#starsObject (readonly)

read-only attributes



102
103
104
# File 'lib/hubba/stats.rb', line 102

def stars
  @stars
end

Instance Method Details

#append(item) ⇒ Object

link items (append item at the end/tail)



112
113
114
115
# File 'lib/hubba/stats.rb', line 112

def append( item )
  @next = item
  item.prev = self
end

#diff_daysObject



117
118
119
120
121
122
123
124
# File 'lib/hubba/stats.rb', line 117

def diff_days
  if @next
    ## note: use jd=julian days for calculation
    @date.jd - @next.date.jd
  else
    nil   ## last item (tail)
  end
end

#diff_starsObject



126
127
128
129
130
131
132
# File 'lib/hubba/stats.rb', line 126

def diff_stars
  if @next
    @stars - @next.stars
  else
    nil   ## last item (tail)
  end
end