Class: JIJI::BaseOut

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jiji/output.rb

Overview

出力先の基底クラス

Direct Known Subclasses

EventOut, GraphOut

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, name, options) ⇒ BaseOut

コンストラクタ



155
156
157
158
159
# File 'lib/jiji/output.rb', line 155

def initialize( dir, name, options )
  @dir = dir
  @dao = JIJI::Dao::TimedDataDao.new( dir, aggregators )
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

補足情報



185
186
187
# File 'lib/jiji/output.rb', line 185

def options
  @options
end

#timeObject

現在時刻



187
188
189
# File 'lib/jiji/output.rb', line 187

def time
  @time
end

Instance Method Details

#each(scale = :raw, start_date = nil, end_date = nil, &block) ⇒ Object

データを読み込む



162
163
164
165
166
# File 'lib/jiji/output.rb', line 162

def each( scale=:raw, start_date=nil, end_date=nil, &block )
  @dao.each_data( scale, start_date, end_date ) { |row, time|
    yield row
  }
end

#saveObject

設定値をファイルに出力



178
179
180
181
182
# File 'lib/jiji/output.rb', line 178

def save
  FileLock.new("#{@dir}/#{JIJI::Output::META_FILE_NAME}" ).writelock { |f|
    f.write( YAML.dump(@options) )
  }
end

#set_properties(props) ⇒ Object

プロパティを設定する。

props

プロパティ



170
171
172
173
174
175
# File 'lib/jiji/output.rb', line 170

def set_properties( props )
  props.each_pair {|k,v|
    @options[k.to_sym] = v
  }
  save
end