Class: JIJI::PeriodicallyRate

Inherits:
Object
  • Object
show all
Includes:
Dao::TimedData, Util::Model
Defined in:
lib/jiji/models.rb

Overview

一定期間のレート

bid,ask,sell_swap,buy_swapの各値が四本値(JIJI::PeriodicallyValue)で保持されます。

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Model

#==, #===, #eql?, #hash

Constructor Details

#initialize(list = []) ⇒ PeriodicallyRate

コンストラクタ

list

初期データ



129
130
131
132
133
134
135
136
137
# File 'lib/jiji/models.rb', line 129

def initialize( list=[] ) #:nodoc:
  @bid = PeriodicallyValue.new
  @ask = PeriodicallyValue.new
  @sell_swap = PeriodicallyValue.new
  @buy_swap  = PeriodicallyValue.new
  list.each { |item|
    self << item
  }
end

Instance Attribute Details

#askObject (readonly)

askレート



171
172
173
# File 'lib/jiji/models.rb', line 171

def ask
  @ask
end

#bidObject (readonly)

bidレート



169
170
171
# File 'lib/jiji/models.rb', line 169

def bid
  @bid
end

#buy_swapObject (readonly)

買いスワップ



175
176
177
# File 'lib/jiji/models.rb', line 175

def buy_swap
  @buy_swap
end

#end_timeObject

集計終了日時



179
180
181
# File 'lib/jiji/models.rb', line 179

def end_time
  @end_time
end

#sell_swapObject (readonly)

売りスワップ



173
174
175
# File 'lib/jiji/models.rb', line 173

def sell_swap
  @sell_swap
end

#start_timeObject

集計開始日時



177
178
179
# File 'lib/jiji/models.rb', line 177

def start_time
  @start_time
end

Instance Method Details

#<<(rate) ⇒ Object

JIJI::Rateを追加し各値の四本値を再計算します。

rate

JIJI::Rate



140
141
142
143
144
145
146
147
# File 'lib/jiji/models.rb', line 140

def <<( rate ) #:nodoc:
  @bid << rate.bid
  @ask << rate.ask
  @sell_swap << rate.sell_swap
  @buy_swap  << rate.buy_swap
  @start_time = rate.time unless @start_time
  @end_time = rate.time
end

#timeObject

:nodoc:



162
163
164
# File 'lib/jiji/models.rb', line 162

def time #:nodoc:
  @end_time
end

#time=(t) ⇒ Object

:nodoc:



165
166
167
# File 'lib/jiji/models.rb', line 165

def time=(t) #:nodoc:
  @end_time = t
end

#valuesObject

値を配列で取得する



149
150
151
152
# File 'lib/jiji/models.rb', line 149

def values #:nodoc:
  bid.values + ask.values + sell_swap.values + buy_swap.values \
    + [@start_time.to_i, @end_time.to_i]
end

#values=(values) ⇒ Object

値を配列で設定する



154
155
156
157
158
159
160
161
# File 'lib/jiji/models.rb', line 154

def values=(values) #:nodoc:
  @bid.values = values[0..3]
  @ask.values = values[4..7]
  @sell_swap.values = values[8..11]
  @buy_swap.values = values[12..15]
  @start_time = Time.at(values[16].to_i)
  @end_time = Time.at(values[17].to_i)
end