Class: RateTheme::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/rate_theme/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Logger

Returns a new instance of Logger.



4
5
6
7
8
# File 'lib/rate_theme/monitor.rb', line 4

def initialize(args)
  @name = args.fetch(:name)
  @rating = args.fetch(:rating)
  @file = File.expand_path("../themes.yml", __FILE__)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rate_theme/monitor.rb', line 3

def name
  @name
end

#ratingObject (readonly)

Returns the value of attribute rating.



3
4
5
# File 'lib/rate_theme/monitor.rb', line 3

def rating
  @rating
end

Instance Method Details

#actionObject



23
24
25
26
27
28
29
# File 'lib/rate_theme/monitor.rb', line 23

def action
  unless File.exists?(@file)
    self.file_virgin
  else
    self.file_exist
  end
end

#file_existObject



17
18
19
20
21
# File 'lib/rate_theme/monitor.rb', line 17

def file_exist
  data = YAML.load_file(@file)
  data[self.name] = self.rating.to_i
  File.open(@file, 'w+') {|f| YAML.dump(data, f)}
end

#file_virginObject



10
11
12
13
14
15
# File 'lib/rate_theme/monitor.rb', line 10

def file_virgin
  File.open(@file, 'w') do |f|
    f.puts({self.name => self.rating.to_i}.to_yaml)
    f.close
  end
end