Class: Bors::Result::Settings

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/bors/result/settings.rb

Constant Summary collapse

SPLIT_SETTINGS_LINE =
/\s=\s/

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Settings

Returns a new instance of Settings.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bors/result/settings.rb', line 10

def initialize(data)
  lines = String.new

  data.each_line do |line|
    break if line.match('average')
    lines += line
  end

  lines.each_line do |line|
    line.match(SPLIT_SETTINGS_LINE) do |m|
      label, value = line.split(SPLIT_SETTINGS_LINE)
      self.send("#{label}=".gsub(' ', '_').downcase, value.gsub("\n", ""))
    end
  end

end

Instance Method Details

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bors/result/settings.rb', line 27

def to_h
  hash = Hash.new
  hash[:final_regressor] = self.final_regressor if self.respond_to?(:final_regressor)
  hash[:num_weight_bits] = self.num_weight_bits.to_i if self.respond_to?(:num_weight_bits)
  hash[:learning_rate] = self.learning_rate.to_i if self.respond_to?(:learning_rate)
  hash[:initial_t] = self.initial_t.to_f if self.respond_to?(:initial_t)
  hash[:power_t] = self.power_t.to_f if self.respond_to?(:power_t)
  hash[:decay_learning_rate] = self.decay_learning_rate.to_i if self.respond_to?(:decay_learning_rate)
  hash[:creating_cache_file] = self.creating_cache_file if self.respond_to?(:creating_cache_file)
  #hash[:reading_from = self.reading_from # not matching due to lack of equals in output
  hash[:num_sources] = self.num_sources.to_i if self.respond_to?(:num_sources)
  hash
end

#to_jsonObject



41
42
43
# File 'lib/bors/result/settings.rb', line 41

def to_json
  Oj.dump(self.to_h)
end